
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.electronic_structure.boltztrap &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.electronic_structure.boltztrap</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.electronic_structure.boltztrap</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module provides classes to run and analyze boltztrap on pymatgen band</span>
<span class="sd">structure objects. Boltztrap is a software interpolating band structures and</span>
<span class="sd">computing materials properties from this band structure using Boltzmann</span>
<span class="sd">semi-classical transport theory.</span>

<span class="sd">Boltztrap has been developed by Georg Madsen.</span>

<span class="sd">http://www.icams.de/content/research/software-development/boltztrap/</span>

<span class="sd">You need version 1.2.3 or higher</span>

<span class="sd">References are::</span>

<span class="sd">    Madsen, G. K. H., and Singh, D. J. (2006).</span>
<span class="sd">    BoltzTraP. A code for calculating band-structure dependent quantities.</span>
<span class="sd">    Computer Physics Communications, 175, 67-71</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">subprocess</span>
<span class="kn">import</span> <span class="nn">tempfile</span>
<span class="kn">import</span> <span class="nn">time</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">monty.dev</span> <span class="kn">import</span> <span class="n">requires</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">jsanitize</span><span class="p">,</span> <span class="n">MSONable</span>
<span class="kn">from</span> <span class="nn">monty.os</span> <span class="kn">import</span> <span class="n">cd</span>
<span class="kn">from</span> <span class="nn">monty.os.path</span> <span class="kn">import</span> <span class="n">which</span>
<span class="kn">from</span> <span class="nn">scipy</span> <span class="kn">import</span> <span class="n">constants</span>
<span class="kn">from</span> <span class="nn">scipy.spatial</span> <span class="kn">import</span> <span class="n">distance</span>

<span class="kn">from</span> <span class="nn">pymatgen.core.lattice</span> <span class="kn">import</span> <span class="n">Lattice</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.units</span> <span class="kn">import</span> <span class="n">Energy</span><span class="p">,</span> <span class="n">Length</span>
<span class="kn">from</span> <span class="nn">pymatgen.electronic_structure.bandstructure</span> <span class="kn">import</span> \
    <span class="n">BandStructureSymmLine</span><span class="p">,</span> <span class="n">Kpoint</span>
<span class="kn">from</span> <span class="nn">pymatgen.electronic_structure.core</span> <span class="kn">import</span> <span class="n">Orbital</span>
<span class="kn">from</span> <span class="nn">pymatgen.electronic_structure.dos</span> <span class="kn">import</span> <span class="n">Dos</span><span class="p">,</span> <span class="n">Spin</span><span class="p">,</span> <span class="n">CompleteDos</span>
<span class="kn">from</span> <span class="nn">pymatgen.symmetry.analyzer</span> <span class="kn">import</span> <span class="n">SpacegroupAnalyzer</span>
<span class="kn">from</span> <span class="nn">pymatgen.symmetry.bandstructure</span> <span class="kn">import</span> <span class="n">HighSymmKpath</span>


<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Geoffroy Hautier, Zachary Gibbs, Francesco Ricci, Anubhav Jain&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2013, The Materials Project&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.1&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Geoffroy Hautier&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;geoffroy@uclouvain.be&quot;</span>
<span class="n">__status__</span> <span class="o">=</span> <span class="s2">&quot;Development&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;August 23, 2013&quot;</span>


<div class="viewcode-block" id="BoltztrapRunner"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapRunner">[docs]</a><span class="k">class</span> <span class="nc">BoltztrapRunner</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This class is used to run Boltztrap on a band structure object.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@requires</span><span class="p">(</span><span class="n">which</span><span class="p">(</span><span class="s1">&#39;x_trans&#39;</span><span class="p">),</span>
              <span class="s2">&quot;BoltztrapRunner requires the executables &#39;x_trans&#39; to be in &quot;</span>
              <span class="s2">&quot;the path. Please download the Boltztrap at http://&quot;</span>
              <span class="s2">&quot;www.icams.de/content/research/software-development/boltztrap/ &quot;</span>
              <span class="s2">&quot;and follow the instructions in the README to compile &quot;</span>
              <span class="s2">&quot;Bolztrap accordingly. Then add x_trans to your path&quot;</span><span class="p">)</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bs</span><span class="p">,</span> <span class="n">nelec</span><span class="p">,</span> <span class="n">dos_type</span><span class="o">=</span><span class="s2">&quot;HISTO&quot;</span><span class="p">,</span> <span class="n">energy_grid</span><span class="o">=</span><span class="mf">0.005</span><span class="p">,</span>
                 <span class="n">lpfac</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">run_type</span><span class="o">=</span><span class="s2">&quot;BOLTZ&quot;</span><span class="p">,</span> <span class="n">band_nb</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">tauref</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">tauexp</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                 <span class="n">tauen</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">soc</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">doping</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">energy_span_around_fermi</span><span class="o">=</span><span class="mf">1.5</span><span class="p">,</span>
                 <span class="n">scissor</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">kpt_line</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">cond_band</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">tmax</span><span class="o">=</span><span class="mi">1300</span><span class="p">,</span> <span class="n">tgrid</span><span class="o">=</span><span class="mi">50</span><span class="p">,</span> <span class="n">symprec</span><span class="o">=</span><span class="mf">1e-3</span><span class="p">,</span> <span class="n">cb_cut</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">7200</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            bs:</span>
<span class="sd">                A band structure object</span>
<span class="sd">            nelec:</span>
<span class="sd">                the number of electrons</span>
<span class="sd">            dos_type:</span>
<span class="sd">                two options for the band structure integration: &quot;HISTO&quot;</span>
<span class="sd">                (histogram) or &quot;TETRA&quot; using the tetrahedon method. TETRA</span>
<span class="sd">                typically gives better results (especially for DOSes)</span>
<span class="sd">                but takes more time</span>
<span class="sd">            energy_grid:</span>
<span class="sd">                the energy steps used for the integration (eV)</span>
<span class="sd">            lpfac:</span>
<span class="sd">                the number of interpolation points in the real space. By</span>
<span class="sd">                default 10 gives 10 time more points in the real space than</span>
<span class="sd">                the number of kpoints given in reciprocal space</span>
<span class="sd">            run_type:</span>
<span class="sd">                type of boltztrap usage. by default</span>
<span class="sd">                - BOLTZ: (default) compute transport coefficients</span>
<span class="sd">                - BANDS: interpolate all bands contained in the energy range</span>
<span class="sd">                specified in energy_span_around_fermi variable, along specified</span>
<span class="sd">                k-points</span>
<span class="sd">                - DOS: compute total and partial dos (custom BoltzTraP code</span>
<span class="sd">                needed!)</span>
<span class="sd">                - FERMI: compute fermi surface or more correctly to</span>
<span class="sd">                get certain bands interpolated</span>
<span class="sd">            band_nb:</span>
<span class="sd">                indicates a band number. Used for Fermi Surface interpolation</span>
<span class="sd">                (run_type=&quot;FERMI&quot;)</span>
<span class="sd">            spin:</span>
<span class="sd">                specific spin component (1: up, -1: down) of the band selected</span>
<span class="sd">                in FERMI mode (mandatory).</span>
<span class="sd">            cond_band:</span>
<span class="sd">                if a conduction band is specified in FERMI mode,</span>
<span class="sd">                set this variable as True</span>
<span class="sd">            tauref:</span>
<span class="sd">                reference relaxation time. Only set to a value different than</span>
<span class="sd">                zero if we want to model beyond the constant relaxation time.</span>
<span class="sd">            tauexp:</span>
<span class="sd">                exponent for the energy in the non-constant relaxation time</span>
<span class="sd">                approach</span>
<span class="sd">            tauen:</span>
<span class="sd">                reference energy for the non-constant relaxation time approach</span>
<span class="sd">            soc:</span>
<span class="sd">                results from spin-orbit coupling (soc) computations give</span>
<span class="sd">                typically non-polarized (no spin up or down) results but single</span>
<span class="sd">                electron occupations. If the band structure comes from a soc</span>
<span class="sd">                computation, you should set soc to True (default False)</span>
<span class="sd">            doping:</span>
<span class="sd">                the fixed doping levels you want to compute. Boltztrap provides</span>
<span class="sd">                both transport values depending on electron chemical potential</span>
<span class="sd">                (fermi energy) and for a series of fixed carrier</span>
<span class="sd">                concentrations. By default, this is set to 1e16 to 1e22 in</span>
<span class="sd">                increments of factors of 10.</span>
<span class="sd">            energy_span_around_fermi:</span>
<span class="sd">                usually the interpolation is not needed on the entire energy</span>
<span class="sd">                range but on a specific range around the fermi level.</span>
<span class="sd">                This energy gives this range in eV. by default it is 1.5 eV.</span>
<span class="sd">                If DOS or BANDS type are selected, this range is automatically</span>
<span class="sd">                set to cover the entire energy range.</span>
<span class="sd">            scissor:</span>
<span class="sd">                scissor to apply to the band gap (eV). This applies a scissor</span>
<span class="sd">                operation moving the band edges without changing the band</span>
<span class="sd">                shape. This is useful to correct the often underestimated band</span>
<span class="sd">                gap in DFT. Default is 0.0 (no scissor)</span>
<span class="sd">            kpt_line:</span>
<span class="sd">                list of fractional coordinates of kpoints as arrays or list of</span>
<span class="sd">                Kpoint objects for BANDS mode calculation (standard path of</span>
<span class="sd">                high symmetry k-points is automatically set as default)</span>
<span class="sd">            tmax:</span>
<span class="sd">                Maximum temperature (K) for calculation (default=1300)</span>
<span class="sd">            tgrid:</span>
<span class="sd">                Temperature interval for calculation (default=50)</span>
<span class="sd">            symprec: 1e-3 is the default in pymatgen. If the kmesh has been</span>
<span class="sd">                generated using a different symprec, it has to be specified</span>
<span class="sd">                to avoid a &quot;factorization error&quot; in BoltzTraP calculation.</span>
<span class="sd">                If a kmesh that spans the whole Brillouin zone has been used,</span>
<span class="sd">                or to disable all the symmetries, set symprec to None.</span>
<span class="sd">            cb_cut: by default 10% of the highest conduction bands are</span>
<span class="sd">                removed because they are often not accurate.</span>
<span class="sd">                Tune cb_cut to change the percentage (0-100) of bands</span>
<span class="sd">                that are removed.</span>
<span class="sd">            timeout: overall time limit (in seconds): mainly to avoid infinite</span>
<span class="sd">                loop when trying to find Fermi levels.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lpfac</span> <span class="o">=</span> <span class="n">lpfac</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span> <span class="o">=</span> <span class="n">bs</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_nelec</span> <span class="o">=</span> <span class="n">nelec</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dos_type</span> <span class="o">=</span> <span class="n">dos_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">energy_grid</span> <span class="o">=</span> <span class="n">energy_grid</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">error</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span> <span class="o">=</span> <span class="n">run_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">band_nb</span> <span class="o">=</span> <span class="n">band_nb</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">spin</span> <span class="o">=</span> <span class="n">spin</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cond_band</span> <span class="o">=</span> <span class="n">cond_band</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tauref</span> <span class="o">=</span> <span class="n">tauref</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tauexp</span> <span class="o">=</span> <span class="n">tauexp</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tauen</span> <span class="o">=</span> <span class="n">tauen</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">soc</span> <span class="o">=</span> <span class="n">soc</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kpt_line</span> <span class="o">=</span> <span class="n">kpt_line</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cb_cut</span> <span class="o">=</span> <span class="n">cb_cut</span> <span class="o">/</span> <span class="mf">100.</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">doping</span><span class="p">,</span> <span class="nb">list</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">doping</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">doping</span> <span class="o">=</span> <span class="n">doping</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">doping</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="p">[</span><span class="mf">1e16</span><span class="p">,</span> <span class="mf">1e17</span><span class="p">,</span> <span class="mf">1e18</span><span class="p">,</span> <span class="mf">1e19</span><span class="p">,</span> <span class="mf">1e20</span><span class="p">,</span> <span class="mf">1e21</span><span class="p">]:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="mi">1</span> <span class="o">*</span> <span class="n">d</span><span class="p">,</span> <span class="mf">2.5</span> <span class="o">*</span> <span class="n">d</span><span class="p">,</span> <span class="mi">5</span> <span class="o">*</span> <span class="n">d</span><span class="p">,</span> <span class="mf">7.5</span> <span class="o">*</span> <span class="n">d</span><span class="p">])</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">1e22</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">energy_span_around_fermi</span> <span class="o">=</span> <span class="n">energy_span_around_fermi</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">scissor</span> <span class="o">=</span> <span class="n">scissor</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tmax</span> <span class="o">=</span> <span class="n">tmax</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tgrid</span> <span class="o">=</span> <span class="n">tgrid</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_symprec</span> <span class="o">=</span> <span class="n">symprec</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;DOS&quot;</span><span class="p">,</span> <span class="s2">&quot;BANDS&quot;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_auto_set_energy_range</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">timeout</span> <span class="o">=</span> <span class="n">timeout</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">start_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">_auto_set_energy_range</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        automatically determine the energy range as min/max eigenvalue</span>
<span class="sd">        minus/plus the buffer_in_ev</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">emins</span> <span class="o">=</span> <span class="p">[</span><span class="nb">min</span><span class="p">([</span><span class="n">e_k</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">e_k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]])]</span>
        <span class="n">emaxs</span> <span class="o">=</span> <span class="p">[</span><span class="nb">max</span><span class="p">([</span><span class="n">e_k</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">e_k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]])]</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">is_spin_polarized</span><span class="p">:</span>
            <span class="n">emins</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">min</span><span class="p">([</span><span class="n">e_k</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">e_k</span> <span class="ow">in</span>
                              <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]]))</span>

            <span class="n">emaxs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">max</span><span class="p">([</span><span class="n">e_k</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">e_k</span> <span class="ow">in</span>
                              <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]]))</span>

        <span class="n">min_eigenval</span> <span class="o">=</span> <span class="n">Energy</span><span class="p">(</span><span class="nb">min</span><span class="p">(</span><span class="n">emins</span><span class="p">)</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="s2">&quot;eV&quot;</span><span class="p">)</span><span class="o">.</span> \
            <span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ry&quot;</span><span class="p">)</span>
        <span class="n">max_eigenval</span> <span class="o">=</span> <span class="n">Energy</span><span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">emaxs</span><span class="p">)</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="s2">&quot;eV&quot;</span><span class="p">)</span><span class="o">.</span> \
            <span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ry&quot;</span><span class="p">)</span>

        <span class="c1"># set energy range to buffer around min/max EV</span>
        <span class="c1"># buffer does not increase CPU time but will help get equal</span>
        <span class="c1"># energies for spin up/down for band structure</span>
        <span class="n">const</span> <span class="o">=</span> <span class="n">Energy</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;eV&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ry&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_ll</span> <span class="o">=</span> <span class="n">min_eigenval</span> <span class="o">-</span> <span class="n">const</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_hl</span> <span class="o">=</span> <span class="n">max_eigenval</span> <span class="o">+</span> <span class="n">const</span>

        <span class="n">en_range</span> <span class="o">=</span> <span class="n">Energy</span><span class="p">(</span><span class="nb">max</span><span class="p">((</span><span class="nb">abs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ll</span><span class="p">),</span> <span class="nb">abs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_hl</span><span class="p">))),</span>
                          <span class="s2">&quot;Ry&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;eV&quot;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">energy_span_around_fermi</span> <span class="o">=</span> <span class="n">en_range</span> <span class="o">*</span> <span class="mf">1.01</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;energy_span_around_fermi = &quot;</span><span class="p">,</span>
              <span class="bp">self</span><span class="o">.</span><span class="n">energy_span_around_fermi</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">bs</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: The BandStructure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">nelec</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: Number of electrons</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nelec</span>

<div class="viewcode-block" id="BoltztrapRunner.write_energy"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapRunner.write_energy">[docs]</a>    <span class="k">def</span> <span class="nf">write_energy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output_file</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Writes the energy to an output file.</span>

<span class="sd">        :param output_file: Filename</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">output_file</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;test</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">kpoints</span><span class="p">)))</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span> <span class="o">==</span> <span class="s2">&quot;FERMI&quot;</span><span class="p">:</span>
                <span class="n">sign</span> <span class="o">=</span> <span class="o">-</span><span class="mf">1.0</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cond_band</span> <span class="k">else</span> <span class="mf">1.0</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">kpoints</span><span class="p">)):</span>
                    <span class="n">eigs</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="n">eigs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Energy</span><span class="p">(</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">spin</span><span class="p">)][</span><span class="bp">self</span><span class="o">.</span><span class="n">band_nb</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="s2">&quot;eV&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ry&quot;</span><span class="p">))</span>
                    <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%12.8f</span><span class="s2"> </span><span class="si">%12.8f</span><span class="s2"> </span><span class="si">%12.8f</span><span class="s2"> </span><span class="si">%d</span><span class="se">\n</span><span class="s2">&quot;</span>
                            <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                               <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                               <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
                               <span class="nb">len</span><span class="p">(</span><span class="n">eigs</span><span class="p">)))</span>
                    <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">eigs</span><span class="p">)):</span>
                        <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%18.8f</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">sign</span> <span class="o">*</span> <span class="nb">float</span><span class="p">(</span><span class="n">eigs</span><span class="p">[</span><span class="n">j</span><span class="p">])))</span>

            <span class="k">else</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">kpt</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">kpoints</span><span class="p">):</span>
                    <span class="n">eigs</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span> <span class="o">==</span> <span class="s2">&quot;DOS&quot;</span><span class="p">:</span>
                        <span class="n">spin_lst</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">spin</span><span class="p">]</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">spin_lst</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">bands</span>

                    <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">spin_lst</span><span class="p">:</span>
                        <span class="c1"># use 90% of bottom bands since highest eigenvalues</span>
                        <span class="c1"># are usually incorrect</span>
                        <span class="c1"># ask Geoffroy Hautier for more details</span>
                        <span class="n">nb_bands</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">nb_bands</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">cb_cut</span><span class="p">)))</span>
                        <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nb_bands</span><span class="p">):</span>
                            <span class="n">eigs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                                <span class="n">Energy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="p">(</span><span class="n">spin</span><span class="p">)][</span><span class="n">j</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span>
                                       <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="s2">&quot;eV&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ry&quot;</span><span class="p">))</span>
                    <span class="n">eigs</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>

                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span> <span class="o">==</span> <span class="s2">&quot;DOS&quot;</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">is_spin_polarized</span><span class="p">:</span>
                        <span class="n">eigs</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ll</span><span class="p">)</span>
                        <span class="n">eigs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_hl</span><span class="p">)</span>

                    <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%12.8f</span><span class="s2"> </span><span class="si">%12.8f</span><span class="s2"> </span><span class="si">%12.8f</span><span class="s2"> </span><span class="si">%d</span><span class="se">\n</span><span class="s2">&quot;</span>
                            <span class="o">%</span> <span class="p">(</span><span class="n">kpt</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                               <span class="n">kpt</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                               <span class="n">kpt</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
                               <span class="nb">len</span><span class="p">(</span><span class="n">eigs</span><span class="p">)))</span>

                    <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">eigs</span><span class="p">)):</span>
                        <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%18.8f</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">eigs</span><span class="p">[</span><span class="n">j</span><span class="p">])))</span></div>

<div class="viewcode-block" id="BoltztrapRunner.write_struct"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapRunner.write_struct">[docs]</a>    <span class="k">def</span> <span class="nf">write_struct</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output_file</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Writes the structure to an output file.</span>

<span class="sd">        :param output_file: Filename</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_symprec</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">sym</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span> <span class="n">symprec</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_symprec</span><span class="p">)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_symprec</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">pass</span>

        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">output_file</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_symprec</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2"> </span><span class="si">{}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">formula</span><span class="p">,</span>
                                         <span class="n">sym</span><span class="o">.</span><span class="n">get_space_group_symbol</span><span class="p">()))</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_symprec</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2"> </span><span class="si">{}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">formula</span><span class="p">,</span>
                                         <span class="s2">&quot;symmetries disabled&quot;</span><span class="p">))</span>

            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span>
                <span class="p">[</span><span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s2">&quot;</span><span class="si">%.5f</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">Length</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="s2">&quot;ang&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;bohr&quot;</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">row</span><span class="p">])</span>
                 <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">matrix</span><span class="p">])))</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_symprec</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">ops</span> <span class="o">=</span> <span class="n">sym</span><span class="o">.</span><span class="n">get_symmetry_dataset</span><span class="p">()[</span><span class="s1">&#39;rotations&#39;</span><span class="p">]</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_symprec</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">ops</span> <span class="o">=</span> <span class="p">[[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]]]</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">ops</span><span class="p">)))</span>

            <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">ops</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">c</span><span class="p">:</span>
                    <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">row</span><span class="p">)))</span></div>

<div class="viewcode-block" id="BoltztrapRunner.write_def"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapRunner.write_def">[docs]</a>    <span class="k">def</span> <span class="nf">write_def</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output_file</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Writes the def to an output file.</span>

<span class="sd">        :param output_file: Filename</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># This function is useless in std version of BoltzTraP code</span>
        <span class="c1"># because x_trans script overwrite BoltzTraP.def</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">output_file</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">so</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">is_spin_polarized</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">soc</span><span class="p">:</span>
                <span class="n">so</span> <span class="o">=</span> <span class="s2">&quot;so&quot;</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;5, &#39;boltztrap.intrans&#39;,      &#39;old&#39;,    &#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;6,&#39;boltztrap.outputtrans&#39;,      &#39;unknown&#39;,    &quot;</span>
                    <span class="s2">&quot;&#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;20,&#39;boltztrap.struct&#39;,         &#39;old&#39;,    &#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span>
                    <span class="o">+</span> <span class="s2">&quot;10,&#39;boltztrap.energy&quot;</span> <span class="o">+</span> <span class="n">so</span> <span class="o">+</span> <span class="s2">&quot;&#39;,         &#39;old&#39;,    &quot;</span>
                                                    <span class="s2">&quot;&#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;48,&#39;boltztrap.engre&#39;,         &#39;unknown&#39;,    &quot;</span>
                    <span class="s2">&quot;&#39;unformatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;49,&#39;boltztrap.transdos&#39;,        &#39;unknown&#39;,    &quot;</span>
                    <span class="s2">&quot;&#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;50,&#39;boltztrap.sigxx&#39;,        &#39;unknown&#39;,    &#39;formatted&#39;,&quot;</span>
                    <span class="s2">&quot;0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;51,&#39;boltztrap.sigxxx&#39;,        &#39;unknown&#39;,    &#39;formatted&#39;,&quot;</span>
                    <span class="s2">&quot;0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;21,&#39;boltztrap.trace&#39;,           &#39;unknown&#39;,    &quot;</span>
                    <span class="s2">&quot;&#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;22,&#39;boltztrap.condtens&#39;,           &#39;unknown&#39;,    &quot;</span>
                    <span class="s2">&quot;&#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;24,&#39;boltztrap.halltens&#39;,           &#39;unknown&#39;,    &quot;</span>
                    <span class="s2">&quot;&#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;30,&#39;boltztrap_BZ.cube&#39;,           &#39;unknown&#39;,    &quot;</span>
                    <span class="s2">&quot;&#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="BoltztrapRunner.write_proj"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapRunner.write_proj">[docs]</a>    <span class="k">def</span> <span class="nf">write_proj</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output_file_proj</span><span class="p">,</span> <span class="n">output_file_def</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Writes the projections to an output file.</span>

<span class="sd">        :param output_file: Filename</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># This function is useless in std version of BoltzTraP code</span>
        <span class="c1"># because x_trans script overwrite BoltzTraP.def</span>
        <span class="k">for</span> <span class="n">oi</span><span class="p">,</span> <span class="n">o</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">Orbital</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">site_nb</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">sites</span><span class="p">)):</span>
                <span class="k">if</span> <span class="n">oi</span> <span class="o">&lt;</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">projections</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]):</span>
                    <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">output_file_proj</span> <span class="o">+</span> <span class="s2">&quot;_&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">site_nb</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;_&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span>
                            <span class="n">o</span><span class="p">),</span>
                              <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
                        <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">formula</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                        <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">kpoints</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">kpoints</span><span class="p">)):</span>
                            <span class="n">tmp_proj</span> <span class="o">=</span> <span class="p">[]</span>
                            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span>
                                    <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">nb_bands</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">cb_cut</span><span class="p">)))):</span>
                                <span class="n">tmp_proj</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                                    <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">projections</span><span class="p">[</span><span class="n">Spin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">spin</span><span class="p">)][</span><span class="n">j</span><span class="p">][</span>
                                        <span class="n">i</span><span class="p">][</span><span class="n">oi</span><span class="p">][</span><span class="n">site_nb</span><span class="p">])</span>
                            <span class="c1"># TODO deal with the sorting going on at</span>
                            <span class="c1"># the energy level!!!</span>
                            <span class="c1"># tmp_proj.sort()</span>

                            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span> <span class="o">==</span> <span class="s2">&quot;DOS&quot;</span> <span class="ow">and</span> \
                                    <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">is_spin_polarized</span><span class="p">:</span>
                                <span class="n">tmp_proj</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ll</span><span class="p">)</span>
                                <span class="n">tmp_proj</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_hl</span><span class="p">)</span>

                            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%12.8f</span><span class="s2"> </span><span class="si">%12.8f</span><span class="s2"> </span><span class="si">%12.8f</span><span class="s2"> </span><span class="si">%d</span><span class="se">\n</span><span class="s2">&quot;</span>
                                    <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                                       <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                                       <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
                                       <span class="nb">len</span><span class="p">(</span><span class="n">tmp_proj</span><span class="p">)))</span>
                            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">tmp_proj</span><span class="p">)):</span>
                                <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%18.8f</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">float</span><span class="p">(</span><span class="n">tmp_proj</span><span class="p">[</span><span class="n">j</span><span class="p">]))</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">output_file_def</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">so</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">is_spin_polarized</span><span class="p">:</span>
                <span class="n">so</span> <span class="o">=</span> <span class="s2">&quot;so&quot;</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;5, &#39;boltztrap.intrans&#39;,      &#39;old&#39;,    &#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;6,&#39;boltztrap.outputtrans&#39;,      &#39;unknown&#39;,    &quot;</span>
                    <span class="s2">&quot;&#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;20,&#39;boltztrap.struct&#39;,         &#39;old&#39;,    &#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span>
                    <span class="o">+</span> <span class="s2">&quot;10,&#39;boltztrap.energy&quot;</span> <span class="o">+</span> <span class="n">so</span> <span class="o">+</span> <span class="s2">&quot;&#39;,         &#39;old&#39;,    &quot;</span>
                                                    <span class="s2">&quot;&#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;48,&#39;boltztrap.engre&#39;,         &#39;unknown&#39;,    &quot;</span>
                    <span class="s2">&quot;&#39;unformatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;49,&#39;boltztrap.transdos&#39;,        &#39;unknown&#39;,    &quot;</span>
                    <span class="s2">&quot;&#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;50,&#39;boltztrap.sigxx&#39;,        &#39;unknown&#39;,    &#39;formatted&#39;,&quot;</span>
                    <span class="s2">&quot;0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;51,&#39;boltztrap.sigxxx&#39;,        &#39;unknown&#39;,    &#39;formatted&#39;,&quot;</span>
                    <span class="s2">&quot;0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;21,&#39;boltztrap.trace&#39;,           &#39;unknown&#39;,    &quot;</span>
                    <span class="s2">&quot;&#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;22,&#39;boltztrap.condtens&#39;,           &#39;unknown&#39;,    &quot;</span>
                    <span class="s2">&quot;&#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;24,&#39;boltztrap.halltens&#39;,           &#39;unknown&#39;,    &quot;</span>
                    <span class="s2">&quot;&#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                    <span class="s2">&quot;30,&#39;boltztrap_BZ.cube&#39;,           &#39;unknown&#39;,    &quot;</span>
                    <span class="s2">&quot;&#39;formatted&#39;,0</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
            <span class="n">i</span> <span class="o">=</span> <span class="mi">1000</span>
            <span class="k">for</span> <span class="n">oi</span><span class="p">,</span> <span class="n">o</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">Orbital</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">site_nb</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">sites</span><span class="p">)):</span>
                    <span class="k">if</span> <span class="n">oi</span> <span class="o">&lt;</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">projections</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]):</span>
                        <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;,</span><span class="se">\&#39;</span><span class="s2">&quot;</span> <span class="o">+</span> <span class="s2">&quot;boltztrap.proj_&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span>
                            <span class="n">site_nb</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;_&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">o</span><span class="o">.</span><span class="n">name</span><span class="p">)</span> <span class="o">+</span>
                                <span class="s2">&quot;</span><span class="se">\&#39;</span><span class="s2"> </span><span class="se">\&#39;</span><span class="s2">old</span><span class="se">\&#39;</span><span class="s2">, </span><span class="se">\&#39;</span><span class="s2">formatted</span><span class="se">\&#39;</span><span class="s2">,0</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                        <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span></div>

<div class="viewcode-block" id="BoltztrapRunner.write_intrans"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapRunner.write_intrans">[docs]</a>    <span class="k">def</span> <span class="nf">write_intrans</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output_file</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Writes the intrans to an output file.</span>

<span class="sd">        :param output_file: Filename</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">setgap</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">scissor</span> <span class="o">&gt;</span> <span class="mf">0.0001</span> <span class="k">else</span> <span class="mi">0</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span> <span class="o">==</span> <span class="s2">&quot;BOLTZ&quot;</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span> <span class="o">==</span> <span class="s2">&quot;DOS&quot;</span><span class="p">:</span>
            <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">output_file</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fout</span><span class="p">:</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;GENE          # use generic interface</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;1 0 </span><span class="si">%d</span><span class="s2"> </span><span class="si">%f</span><span class="s2">         # iskip (not presently used) idebug &quot;</span>
                    <span class="s2">&quot;setgap shiftgap </span><span class="se">\n</span><span class="s2">&quot;</span>
                    <span class="o">%</span> <span class="p">(</span><span class="n">setgap</span><span class="p">,</span> <span class="n">Energy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scissor</span><span class="p">,</span> <span class="s2">&quot;eV&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ry&quot;</span><span class="p">)))</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;0.0 </span><span class="si">%f</span><span class="s2"> </span><span class="si">%f</span><span class="s2"> </span><span class="si">%6.1f</span><span class="s2">     # Fermilevel (Ry),energygrid,energy &quot;</span>
                    <span class="s2">&quot;span around Fermilevel, number of electrons</span><span class="se">\n</span><span class="s2">&quot;</span>
                    <span class="o">%</span> <span class="p">(</span><span class="n">Energy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energy_grid</span><span class="p">,</span> <span class="s2">&quot;eV&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ry&quot;</span><span class="p">),</span>
                       <span class="n">Energy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energy_span_around_fermi</span><span class="p">,</span> <span class="s2">&quot;eV&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ry&quot;</span><span class="p">),</span>
                       <span class="bp">self</span><span class="o">.</span><span class="n">_nelec</span><span class="p">))</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;CALC                    # CALC (calculate expansion &quot;</span>
                    <span class="s2">&quot;coeff), NOCALC read from file</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;</span><span class="si">%d</span><span class="s2">                        # lpfac, number of latt-points &quot;</span>
                    <span class="s2">&quot;per k-point</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">lpfac</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">                     # run mode (only BOLTZ is &quot;</span>
                    <span class="s2">&quot;supported)</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;.15                       # (efcut) energy range of &quot;</span>
                    <span class="s2">&quot;chemical potential</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;</span><span class="si">{}</span><span class="s2"> </span><span class="si">{}</span><span class="s2">                  # Tmax, temperature grid</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span>
                    <span class="nb">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tmax</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tgrid</span><span class="p">))</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;-1.  # energyrange of bands given DOS output sig_xxx and &quot;</span>
                    <span class="s2">&quot;dos_xxx (xxx is band number)</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dos_type</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>  <span class="c1"># e.g., HISTO or TETRA</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> 0 0 0</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">tauref</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tauexp</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tauen</span><span class="p">))</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="p">)))</span>

                <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="p">:</span>
                    <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="p">:</span>
                    <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="o">-</span><span class="n">d</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>

        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span> <span class="o">==</span> <span class="s2">&quot;FERMI&quot;</span><span class="p">:</span>
            <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">output_file</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fout</span><span class="p">:</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;GENE          # use generic interface</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;1 0 0 0.0         # iskip (not presently used) idebug &quot;</span>
                    <span class="s2">&quot;setgap shiftgap </span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;0.0 </span><span class="si">%f</span><span class="s2"> 0.1 </span><span class="si">%6.1f</span><span class="s2">     # Fermilevel (Ry),energygrid,&quot;</span>
                    <span class="s2">&quot;energy span around Fermilevel, &quot;</span>
                    <span class="s2">&quot;number of electrons</span><span class="se">\n</span><span class="s2">&quot;</span>
                    <span class="o">%</span> <span class="p">(</span><span class="n">Energy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energy_grid</span><span class="p">,</span> <span class="s2">&quot;eV&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ry&quot;</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nelec</span><span class="p">))</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;CALC                    # CALC (calculate expansion &quot;</span>
                    <span class="s2">&quot;coeff), NOCALC read from file</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;</span><span class="si">%d</span><span class="s2">                        # lpfac, number of latt-points &quot;</span>
                    <span class="s2">&quot;per k-point</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">lpfac</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;FERMI                     # run mode (only BOLTZ is &quot;</span>
                    <span class="s2">&quot;supported)</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span>
                           <span class="s2">&quot;                        # actual band selected: &quot;</span> <span class="o">+</span>
                           <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">band_nb</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; spin: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">spin</span><span class="p">))</span>

        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span> <span class="o">==</span> <span class="s2">&quot;BANDS&quot;</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpt_line</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">kpath</span> <span class="o">=</span> <span class="n">HighSymmKpath</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">kpt_line</span> <span class="o">=</span> <span class="p">[</span><span class="n">Kpoint</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span>
                                 <span class="ow">in</span>
                                 <span class="n">kpath</span><span class="o">.</span><span class="n">get_kpoints</span><span class="p">(</span><span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">)[</span>
                                     <span class="mi">0</span><span class="p">]]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">kpt_line</span> <span class="o">=</span> <span class="p">[</span><span class="n">kp</span><span class="o">.</span><span class="n">frac_coords</span> <span class="k">for</span> <span class="n">kp</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpt_line</span><span class="p">]</span>
            <span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpt_line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="n">Kpoint</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">kpt_line</span> <span class="o">=</span> <span class="p">[</span><span class="n">kp</span><span class="o">.</span><span class="n">frac_coords</span> <span class="k">for</span> <span class="n">kp</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpt_line</span><span class="p">]</span>

            <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">output_file</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fout</span><span class="p">:</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;GENE          # use generic interface</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;1 0 </span><span class="si">%d</span><span class="s2"> </span><span class="si">%f</span><span class="s2">         # iskip (not presently used) idebug &quot;</span>
                    <span class="s2">&quot;setgap shiftgap </span><span class="se">\n</span><span class="s2">&quot;</span>
                    <span class="o">%</span> <span class="p">(</span><span class="n">setgap</span><span class="p">,</span> <span class="n">Energy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scissor</span><span class="p">,</span> <span class="s2">&quot;eV&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ry&quot;</span><span class="p">)))</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;0.0 </span><span class="si">%f</span><span class="s2"> </span><span class="si">%f</span><span class="s2"> </span><span class="si">%6.1f</span><span class="s2">     # Fermilevel (Ry),energygrid,energy &quot;</span>
                    <span class="s2">&quot;span around Fermilevel, &quot;</span>
                    <span class="s2">&quot;number of electrons</span><span class="se">\n</span><span class="s2">&quot;</span>
                    <span class="o">%</span> <span class="p">(</span><span class="n">Energy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energy_grid</span><span class="p">,</span> <span class="s2">&quot;eV&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ry&quot;</span><span class="p">),</span>
                       <span class="n">Energy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energy_span_around_fermi</span><span class="p">,</span> <span class="s2">&quot;eV&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ry&quot;</span><span class="p">),</span>
                       <span class="bp">self</span><span class="o">.</span><span class="n">_nelec</span><span class="p">))</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;CALC                    # CALC (calculate expansion &quot;</span>
                    <span class="s2">&quot;coeff), NOCALC read from file</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;</span><span class="si">%d</span><span class="s2">                        # lpfac, number of latt-points &quot;</span>
                    <span class="s2">&quot;per k-point</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">lpfac</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span>
                    <span class="s2">&quot;BANDS                     # run mode (only BOLTZ is &quot;</span>
                    <span class="s2">&quot;supported)</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;P &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpt_line</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">kp</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpt_line</span><span class="p">:</span>
                    <span class="n">fout</span><span class="o">.</span><span class="n">writelines</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">kp</span><span class="p">])</span>
                    <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span></div>

<div class="viewcode-block" id="BoltztrapRunner.write_input"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapRunner.write_input">[docs]</a>    <span class="k">def</span> <span class="nf">write_input</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output_dir</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Writes the input files.</span>

<span class="sd">        :param output_dir: Directory to write the input files.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">is_spin_polarized</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">soc</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">write_energy</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap.energyso&quot;</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">write_energy</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap.energy&quot;</span><span class="p">))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">write_struct</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap.struct&quot;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">write_intrans</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap.intrans&quot;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">write_def</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output_dir</span><span class="p">,</span> <span class="s2">&quot;BoltzTraP.def&quot;</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bs</span><span class="o">.</span><span class="n">projections</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span> <span class="o">==</span> <span class="s2">&quot;DOS&quot;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">write_proj</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap.proj&quot;</span><span class="p">),</span>
                            <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output_dir</span><span class="p">,</span> <span class="s2">&quot;BoltzTraP.def&quot;</span><span class="p">))</span></div>

<div class="viewcode-block" id="BoltztrapRunner.run"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapRunner.run">[docs]</a>    <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path_dir</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">convergence</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">write_input</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
            <span class="n">clear_dir</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">max_lpfac</span><span class="o">=</span><span class="mi">150</span><span class="p">,</span> <span class="n">min_egrid</span><span class="o">=</span><span class="mf">0.00005</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Write inputs (optional), run BoltzTraP, and ensure</span>
<span class="sd">        convergence (optional)</span>
<span class="sd">        Args:</span>
<span class="sd">            path_dir (str): directory in which to run BoltzTraP</span>
<span class="sd">            convergence (bool): whether to check convergence and make</span>
<span class="sd">                corrections if needed</span>
<span class="sd">            write_input: (bool) whether to write input files before the run</span>
<span class="sd">                (required for convergence mode)</span>
<span class="sd">            clear_dir: (bool) whether to remove all files in the path_dir</span>
<span class="sd">                before starting</span>
<span class="sd">            max_lpfac: (float) maximum lpfac value to try before reducing egrid</span>
<span class="sd">                in convergence mode</span>
<span class="sd">            min_egrid: (float) minimum egrid value to try before giving up in</span>
<span class="sd">                convergence mode</span>

<span class="sd">        Returns:</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># TODO: consider making this a part of custodian rather than pymatgen</span>
        <span class="c1"># A lot of this functionality (scratch dirs, handlers, monitors)</span>
        <span class="c1"># is built into custodian framework</span>

        <span class="k">if</span> <span class="n">convergence</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">write_input</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Convergence mode requires write_input to be &quot;</span>
                             <span class="s2">&quot;true&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;BANDS&quot;</span><span class="p">,</span> <span class="s2">&quot;DOS&quot;</span><span class="p">,</span> <span class="s2">&quot;FERMI&quot;</span><span class="p">):</span>
            <span class="n">convergence</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">lpfac</span> <span class="o">&gt;</span> <span class="n">max_lpfac</span><span class="p">:</span>
                <span class="n">max_lpfac</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lpfac</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span> <span class="o">==</span> <span class="s2">&quot;BANDS&quot;</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">bs</span><span class="o">.</span><span class="n">is_spin_polarized</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Reminder: for run_type &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;, spin component are not separated! &quot;</span>
                                 <span class="s2">&quot;(you have a spin polarized band structure)&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;FERMI&quot;</span><span class="p">,</span> <span class="s2">&quot;DOS&quot;</span><span class="p">)</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">spin</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bs</span><span class="o">.</span><span class="n">is_spin_polarized</span><span class="p">:</span>
                <span class="k">raise</span> <span class="n">BoltztrapError</span><span class="p">(</span>
                    <span class="s2">&quot;Spin parameter must be specified for spin polarized &quot;</span>
                    <span class="s2">&quot;band structures!&quot;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">spin</span> <span class="o">=</span> <span class="mi">1</span>

        <span class="n">dir_bz_name</span> <span class="o">=</span> <span class="s2">&quot;boltztrap&quot;</span>
        <span class="k">if</span> <span class="n">path_dir</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">temp_dir</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">()</span>
            <span class="n">path_dir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">temp_dir</span><span class="p">,</span> <span class="n">dir_bz_name</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">path_dir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span>
                <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="n">dir_bz_name</span><span class="p">))</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">path_dir</span><span class="p">):</span>
            <span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">path_dir</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">clear_dir</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">path_dir</span><span class="p">):</span>
                <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="n">c</span><span class="p">))</span>

        <span class="n">FORMAT</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">%(message)s</span><span class="s2">&quot;</span>
        <span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="n">FORMAT</span><span class="p">,</span>
                            <span class="n">filename</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s2">&quot;../boltztrap.out&quot;</span><span class="p">))</span>

        <span class="k">with</span> <span class="n">cd</span><span class="p">(</span><span class="n">path_dir</span><span class="p">):</span>
            <span class="n">lpfac_start</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lpfac</span>
            <span class="n">converged</span> <span class="o">=</span> <span class="kc">False</span>

            <span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">energy_grid</span> <span class="o">&gt;=</span> <span class="n">min_egrid</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">converged</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">lpfac</span> <span class="o">=</span> <span class="n">lpfac_start</span>
                <span class="k">if</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">start_time</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">timeout</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="n">BoltztrapError</span><span class="p">(</span><span class="s2">&quot;no doping convergence after timeout &quot;</span>
                                         <span class="s2">&quot;of </span><span class="si">{}</span><span class="s2"> s&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">timeout</span><span class="p">))</span>

                <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;lpfac, energy_grid: </span><span class="si">{}</span><span class="s2"> </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lpfac</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energy_grid</span><span class="p">))</span>

                <span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">lpfac</span> <span class="o">&lt;=</span> <span class="n">max_lpfac</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">converged</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">start_time</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">timeout</span><span class="p">:</span>
                        <span class="k">raise</span> <span class="n">BoltztrapError</span><span class="p">(</span><span class="s2">&quot;no doping convergence after &quot;</span>
                                             <span class="s2">&quot;timeout of </span><span class="si">{}</span><span class="s2"> s&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">timeout</span><span class="p">))</span>

                    <span class="k">if</span> <span class="n">write_input</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">write_input</span><span class="p">(</span><span class="n">path_dir</span><span class="p">)</span>

                    <span class="n">bt_exe</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;x_trans&quot;</span><span class="p">,</span> <span class="s2">&quot;BoltzTraP&quot;</span><span class="p">]</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bs</span><span class="o">.</span><span class="n">is_spin_polarized</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">soc</span><span class="p">:</span>
                        <span class="n">bt_exe</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;-so&quot;</span><span class="p">)</span>

                    <span class="n">p</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">Popen</span><span class="p">(</span><span class="n">bt_exe</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span>
                                         <span class="n">stdin</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span>
                                         <span class="n">stderr</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">)</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>

                    <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">communicate</span><span class="p">():</span>
                        <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">decode</span><span class="p">())</span>
                        <span class="k">if</span> <span class="s2">&quot;error in factorization&quot;</span> <span class="ow">in</span> <span class="n">c</span><span class="o">.</span><span class="n">decode</span><span class="p">():</span>
                            <span class="k">raise</span> <span class="n">BoltztrapError</span><span class="p">(</span><span class="s2">&quot;error in factorization&quot;</span><span class="p">)</span>

                    <span class="n">warning</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>

                    <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span>
                                           <span class="n">dir_bz_name</span> <span class="o">+</span> <span class="s2">&quot;.outputtrans&quot;</span><span class="p">))</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
                        <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                            <span class="k">if</span> <span class="s2">&quot;Option unknown&quot;</span> <span class="ow">in</span> <span class="n">l</span><span class="p">:</span>
                                <span class="k">raise</span> <span class="n">BoltztrapError</span><span class="p">(</span>
                                    <span class="s2">&quot;DOS mode needs a custom version of &quot;</span>
                                    <span class="s2">&quot;BoltzTraP code is needed&quot;</span><span class="p">)</span>
                            <span class="k">if</span> <span class="s2">&quot;WARNING&quot;</span> <span class="ow">in</span> <span class="n">l</span><span class="p">:</span>
                                <span class="n">warning</span> <span class="o">=</span> <span class="n">l</span>
                                <span class="k">break</span>
                            <span class="k">if</span> <span class="s2">&quot;Error - Fermi level was not found&quot;</span> <span class="ow">in</span> <span class="n">l</span><span class="p">:</span>
                                <span class="n">warning</span> <span class="o">=</span> <span class="n">l</span>
                                <span class="k">break</span>

                    <span class="k">if</span> <span class="ow">not</span> <span class="n">warning</span> <span class="ow">and</span> <span class="n">convergence</span><span class="p">:</span>
                        <span class="c1"># check convergence for warning</span>
                        <span class="n">analyzer</span> <span class="o">=</span> <span class="n">BoltztrapAnalyzer</span><span class="o">.</span><span class="n">from_files</span><span class="p">(</span><span class="n">path_dir</span><span class="p">)</span>
                        <span class="k">for</span> <span class="n">doping</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="s1">&#39;p&#39;</span><span class="p">]:</span>
                            <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">analyzer</span><span class="o">.</span><span class="n">mu_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">]:</span>
                                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">analyzer</span><span class="o">.</span><span class="n">mu_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">c</span><span class="p">])</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span>
                                        <span class="n">analyzer</span><span class="o">.</span><span class="n">doping</span><span class="p">[</span><span class="n">doping</span><span class="p">]):</span>
                                    <span class="n">warning</span> <span class="o">=</span> <span class="s2">&quot;length of mu_doping array is &quot;</span> \
                                              <span class="s2">&quot;incorrect&quot;</span>
                                    <span class="k">break</span>

                                <span class="k">if</span> <span class="n">doping</span> <span class="o">==</span> <span class="s1">&#39;p&#39;</span> <span class="ow">and</span> \
                                        <span class="nb">sorted</span><span class="p">(</span>
                                            <span class="n">analyzer</span><span class="o">.</span><span class="n">mu_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span>
                                                <span class="n">c</span><span class="p">],</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="o">!=</span> \
                                        <span class="n">analyzer</span><span class="o">.</span><span class="n">mu_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">c</span><span class="p">]:</span>
                                    <span class="n">warning</span> <span class="o">=</span> <span class="s2">&quot;sorting of mu_doping array &quot;</span> \
                                              <span class="s2">&quot;incorrect for p-type&quot;</span>
                                    <span class="k">break</span>

                                <span class="c1"># ensure n-type doping sorted correctly</span>
                                <span class="k">if</span> <span class="n">doping</span> <span class="o">==</span> <span class="s1">&#39;n&#39;</span> <span class="ow">and</span> <span class="nb">sorted</span><span class="p">(</span>
                                        <span class="n">analyzer</span><span class="o">.</span><span class="n">mu_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">c</span><span class="p">])</span> <span class="o">!=</span> \
                                        <span class="n">analyzer</span><span class="o">.</span><span class="n">mu_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">c</span><span class="p">]:</span>
                                    <span class="n">warning</span> <span class="o">=</span> <span class="s2">&quot;sorting of mu_doping array &quot;</span> \
                                              <span class="s2">&quot;incorrect for n-type&quot;</span>
                                    <span class="k">break</span>

                    <span class="k">if</span> <span class="n">warning</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">lpfac</span> <span class="o">+=</span> <span class="mi">10</span>
                        <span class="n">logging</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;Warning detected: </span><span class="si">{}</span><span class="s2">! Increase lpfac to &quot;</span>
                                     <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">warning</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">lpfac</span><span class="p">))</span>

                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">converged</span> <span class="o">=</span> <span class="kc">True</span>

                <span class="k">if</span> <span class="ow">not</span> <span class="n">converged</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">energy_grid</span> <span class="o">/=</span> <span class="mi">10</span>
                    <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Could not converge with max lpfac; &quot;</span>
                                 <span class="s2">&quot;Decrease egrid to </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energy_grid</span><span class="p">))</span>

            <span class="k">if</span> <span class="ow">not</span> <span class="n">converged</span><span class="p">:</span>
                <span class="k">raise</span> <span class="n">BoltztrapError</span><span class="p">(</span>
                    <span class="s2">&quot;Doping convergence not reached with lpfac=&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">lpfac</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;, energy_grid=&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energy_grid</span><span class="p">))</span>

            <span class="k">return</span> <span class="n">path_dir</span></div>

<div class="viewcode-block" id="BoltztrapRunner.as_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapRunner.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: MSONable dict</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">results</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
                   <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                   <span class="s2">&quot;lpfac&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">lpfac</span><span class="p">,</span>
                   <span class="s2">&quot;bs&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">bs</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
                   <span class="s2">&quot;nelec&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nelec</span><span class="p">,</span>
                   <span class="s2">&quot;dos_type&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">dos_type</span><span class="p">,</span>
                   <span class="s2">&quot;run_type&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span><span class="p">,</span>
                   <span class="s2">&quot;band_nb&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">band_nb</span><span class="p">,</span>
                   <span class="s2">&quot;spin&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">spin</span><span class="p">,</span>
                   <span class="s2">&quot;cond_band&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">cond_band</span><span class="p">,</span>
                   <span class="s2">&quot;tauref&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">tauref</span><span class="p">,</span>
                   <span class="s2">&quot;tauexp&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">tauexp</span><span class="p">,</span>
                   <span class="s2">&quot;tauen&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">tauen</span><span class="p">,</span>
                   <span class="s2">&quot;soc&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">soc</span><span class="p">,</span>
                   <span class="s2">&quot;kpt_line&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpt_line</span><span class="p">,</span>
                   <span class="s2">&quot;doping&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="p">,</span>
                   <span class="s2">&quot;energy_span_around_fermi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">energy_span_around_fermi</span><span class="p">,</span>
                   <span class="s2">&quot;scissor&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">scissor</span><span class="p">,</span>
                   <span class="s2">&quot;tmax&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">tmax</span><span class="p">,</span>
                   <span class="s2">&quot;tgrid&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">tgrid</span><span class="p">,</span>
                   <span class="s2">&quot;symprec&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_symprec</span>
                   <span class="p">}</span>
        <span class="k">return</span> <span class="n">jsanitize</span><span class="p">(</span><span class="n">results</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="BoltztrapError"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapError">[docs]</a><span class="k">class</span> <span class="nc">BoltztrapError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Exception class for boltztrap.</span>
<span class="sd">    Raised when the boltztrap gives an error</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">pass</span></div>


<div class="viewcode-block" id="BoltztrapAnalyzer"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer">[docs]</a><span class="k">class</span> <span class="nc">BoltztrapAnalyzer</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class used to store all the data from a boltztrap run</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">gap</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">mu_steps</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">cond</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">seebeck</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">kappa</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">hall</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">doping</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">mu_doping</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">seebeck_doping</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">cond_doping</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">kappa_doping</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">hall_doping</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">intrans</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">dos</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">dos_partial</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">carrier_conc</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">vol</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">warning</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">bz_bands</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">bz_kpoints</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">fermi_surface_data</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor taking directly all the data generated by Boltztrap. You</span>
<span class="sd">        won&#39;t probably use it directly but instead use the from_files and</span>
<span class="sd">        from_dict methods.</span>

<span class="sd">        Args:</span>
<span class="sd">            gap: The gap after interpolation in eV</span>
<span class="sd">            mu_steps: The steps of electron chemical potential (or Fermi</span>
<span class="sd">                level) in eV.</span>
<span class="sd">            cond: The electronic conductivity tensor divided by a constant</span>
<span class="sd">                relaxation time (sigma/tau) at different temperature and</span>
<span class="sd">                fermi levels.</span>
<span class="sd">                The format is {temperature: [array of 3x3 tensors at each</span>
<span class="sd">                fermi level in mu_steps]}. The units are 1/(Ohm*m*s).</span>
<span class="sd">            seebeck: The Seebeck tensor at different temperatures and fermi</span>
<span class="sd">                levels. The format is {temperature: [array of 3x3 tensors at</span>
<span class="sd">                each fermi level in mu_steps]}. The units are V/K</span>
<span class="sd">            kappa: The electronic thermal conductivity tensor divided by a</span>
<span class="sd">                constant relaxation time (kappa/tau) at different temperature</span>
<span class="sd">                and fermi levels. The format is {temperature: [array of 3x3</span>
<span class="sd">                tensors at each fermi level in mu_steps]}</span>
<span class="sd">                The units are W/(m*K*s)</span>
<span class="sd">            hall: The hall tensor at different temperature and fermi levels</span>
<span class="sd">                The format is {temperature: [array of 27 coefficients list at</span>
<span class="sd">                each fermi level in mu_steps]}</span>
<span class="sd">                The units are m^3/C</span>
<span class="sd">            doping: The different doping levels that have been given to</span>
<span class="sd">                Boltztrap. The format is {&#39;p&#39;:[],&#39;n&#39;:[]} with an array of</span>
<span class="sd">                doping levels. The units are cm^-3</span>
<span class="sd">            mu_doping: Gives the electron chemical potential (or Fermi level)</span>
<span class="sd">                for a given set of doping.</span>
<span class="sd">                Format is {&#39;p&#39;:{temperature: [fermi levels],&#39;n&#39;:{temperature:</span>
<span class="sd">                [fermi levels]}}</span>
<span class="sd">                the fermi level array is ordered according to the doping</span>
<span class="sd">                levels in doping units for doping are in cm^-3 and for Fermi</span>
<span class="sd">                level in eV</span>
<span class="sd">            seebeck_doping: The Seebeck tensor at different temperatures and</span>
<span class="sd">                doping levels. The format is {&#39;p&#39;: {temperature: [Seebeck</span>
<span class="sd">                tensors]}, &#39;n&#39;:{temperature: [Seebeck tensors]}}</span>
<span class="sd">                The [Seebeck tensors] array is ordered according to the</span>
<span class="sd">                doping levels in doping units for doping are in cm^-3 and for</span>
<span class="sd">                Seebeck in V/K</span>
<span class="sd">            cond_doping: The electronic conductivity tensor divided by a</span>
<span class="sd">                constant relaxation time (sigma/tau) at different</span>
<span class="sd">                temperatures and doping levels</span>
<span class="sd">                The format is {&#39;p&#39;:{temperature: [conductivity tensors]},</span>
<span class="sd">                &#39;n&#39;:{temperature: [conductivity tensors]}}</span>
<span class="sd">                The [conductivity tensors] array is ordered according to the</span>
<span class="sd">                doping levels in doping units for doping are in cm^-3 and for</span>
<span class="sd">                conductivity in 1/(Ohm*m*s)</span>
<span class="sd">            kappa_doping: The thermal conductivity tensor divided by a constant</span>
<span class="sd">                relaxation time (kappa/tau) at different temperatures and</span>
<span class="sd">                doping levels.</span>
<span class="sd">                The format is {&#39;p&#39;:{temperature: [thermal conductivity</span>
<span class="sd">                tensors]},&#39;n&#39;:{temperature: [thermal conductivity tensors]}}</span>
<span class="sd">                The [thermal conductivity tensors] array is ordered according</span>
<span class="sd">                to the doping levels in doping units for doping are in cm^-3</span>
<span class="sd">                and for thermal conductivity in W/(m*K*s)</span>
<span class="sd">            hall_doping: The Hall tensor at different temperatures and doping</span>
<span class="sd">                levels.</span>
<span class="sd">                The format is {&#39;p&#39;:{temperature: [Hall tensors]},</span>
<span class="sd">                &#39;n&#39;:{temperature: [Hall tensors]}}</span>
<span class="sd">                The [Hall tensors] array is ordered according to the doping</span>
<span class="sd">                levels in doping and each Hall tensor is represented by a 27</span>
<span class="sd">                coefficients list.</span>
<span class="sd">                The units are m^3/C</span>
<span class="sd">            intrans: a dictionary of inputs e.g. {&quot;scissor&quot;: 0.0}</span>
<span class="sd">            carrier_conc: The concentration of carriers in electron (or hole)</span>
<span class="sd">                per unit cell</span>
<span class="sd">            dos: The dos computed by Boltztrap given as a pymatgen Dos object</span>
<span class="sd">            dos_partial: Data for the partial DOS projected on sites and</span>
<span class="sd">                orbitals</span>
<span class="sd">            vol: Volume of the unit cell in angstrom cube (A^3)</span>
<span class="sd">            warning: string if BoltzTraP outputted a warning, else None</span>
<span class="sd">            bz_bands: Data for interpolated bands on a k-point line</span>
<span class="sd">                (run_type=BANDS)</span>
<span class="sd">            bz_kpoints: k-point in reciprocal coordinates for interpolated</span>
<span class="sd">                bands (run_type=BANDS)</span>
<span class="sd">            fermi_surface_data: energy values in a 3D grid imported from the</span>
<span class="sd">                output .cube file.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">gap</span> <span class="o">=</span> <span class="n">gap</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mu_steps</span> <span class="o">=</span> <span class="n">mu_steps</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_cond</span> <span class="o">=</span> <span class="n">cond</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck</span> <span class="o">=</span> <span class="n">seebeck</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_kappa</span> <span class="o">=</span> <span class="n">kappa</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_hall</span> <span class="o">=</span> <span class="n">hall</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">warning</span> <span class="o">=</span> <span class="n">warning</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">doping</span> <span class="o">=</span> <span class="n">doping</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mu_doping</span> <span class="o">=</span> <span class="n">mu_doping</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span> <span class="o">=</span> <span class="n">seebeck_doping</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_cond_doping</span> <span class="o">=</span> <span class="n">cond_doping</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_kappa_doping</span> <span class="o">=</span> <span class="n">kappa_doping</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_hall_doping</span> <span class="o">=</span> <span class="n">hall_doping</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">intrans</span> <span class="o">=</span> <span class="n">intrans</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_carrier_conc</span> <span class="o">=</span> <span class="n">carrier_conc</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dos</span> <span class="o">=</span> <span class="n">dos</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">vol</span> <span class="o">=</span> <span class="n">vol</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_dos_partial</span> <span class="o">=</span> <span class="n">dos_partial</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bz_bands</span> <span class="o">=</span> <span class="n">bz_bands</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bz_kpoints</span> <span class="o">=</span> <span class="n">bz_kpoints</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fermi_surface_data</span> <span class="o">=</span> <span class="n">fermi_surface_data</span>

<div class="viewcode-block" id="BoltztrapAnalyzer.get_symm_bands"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.get_symm_bands">[docs]</a>    <span class="k">def</span> <span class="nf">get_symm_bands</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">efermi</span><span class="p">,</span> <span class="n">kpt_line</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                       <span class="n">labels_dict</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Function useful to read bands from Boltztrap output and get a</span>
<span class="sd">            BandStructureSymmLine object comparable with that one from a DFT</span>
<span class="sd">            calculation (if the same kpt_line is provided). Default kpt_line</span>
<span class="sd">            and labels_dict is the standard path of high symmetry k-point for</span>
<span class="sd">            the specified structure. They could be extracted from the</span>
<span class="sd">            BandStructureSymmLine object that you want to compare with. efermi</span>
<span class="sd">            variable must be specified to create the BandStructureSymmLine</span>
<span class="sd">            object (usually it comes from DFT or Boltztrap calc)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">kpt_line</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">kpath</span> <span class="o">=</span> <span class="n">HighSymmKpath</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>
                <span class="n">kpt_line</span> <span class="o">=</span> <span class="p">[</span><span class="n">Kpoint</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">reciprocal_lattice</span><span class="p">)</span> <span class="k">for</span>
                            <span class="n">k</span> <span class="ow">in</span>
                            <span class="n">kpath</span><span class="o">.</span><span class="n">get_kpoints</span><span class="p">(</span><span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">)[</span><span class="mi">0</span><span class="p">]]</span>
                <span class="n">labels_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">l</span><span class="p">:</span> <span class="n">k</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">l</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span>
                    <span class="o">*</span><span class="n">kpath</span><span class="o">.</span><span class="n">get_kpoints</span><span class="p">(</span><span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span> <span class="k">if</span> <span class="n">l</span><span class="p">}</span>
                <span class="n">kpt_line</span> <span class="o">=</span> <span class="p">[</span><span class="n">kp</span><span class="o">.</span><span class="n">frac_coords</span> <span class="k">for</span> <span class="n">kp</span> <span class="ow">in</span> <span class="n">kpt_line</span><span class="p">]</span>
            <span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">kpt_line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="n">Kpoint</span><span class="p">:</span>
                <span class="n">kpt_line</span> <span class="o">=</span> <span class="p">[</span><span class="n">kp</span><span class="o">.</span><span class="n">frac_coords</span> <span class="k">for</span> <span class="n">kp</span> <span class="ow">in</span> <span class="n">kpt_line</span><span class="p">]</span>
                <span class="n">labels_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">labels_dict</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">frac_coords</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span>
                               <span class="n">labels_dict</span><span class="p">}</span>

            <span class="n">idx_list</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="c1">#       kpt_dense=np.array([kp for kp in self._bz_kpoints])</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">kp</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">kpt_line</span><span class="p">):</span>
                <span class="n">w</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">prec</span> <span class="o">=</span> <span class="mf">1e-05</span>
                <span class="k">while</span> <span class="nb">len</span><span class="p">(</span><span class="n">w</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">w</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">all</span><span class="p">(</span>
                        <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">kp</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bz_kpoints</span><span class="p">)</span> <span class="o">&lt;</span> <span class="p">[</span><span class="n">prec</span><span class="p">]</span> <span class="o">*</span> <span class="mi">3</span><span class="p">,</span>
                        <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="n">prec</span> <span class="o">*=</span> <span class="mi">10</span>

                <span class="c1"># print( prec )</span>
                <span class="n">idx_list</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">i</span><span class="p">,</span> <span class="n">w</span><span class="p">[</span><span class="mi">0</span><span class="p">]])</span>

                <span class="c1"># if len(w)&gt;0:</span>
                <span class="c1">#     idx_list.append([i,w[0]])</span>
                <span class="c1"># else:</span>
                <span class="c1">#     w=np.where(np.all(np.abs(kp.frac_coords-self._bz_kpoints)</span>
                <span class="c1"># &lt;[1e-04,1e-04,1e-04],axis=1))[0]</span>
                <span class="c1">#     idx_list.append([i,w[0]])</span>

            <span class="n">idx_list</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">idx_list</span><span class="p">)</span>
            <span class="c1"># print( idx_list.shape )</span>

            <span class="n">bands_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">:</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bz_bands</span> <span class="o">*</span> <span class="n">Energy</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;Ry&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span>
                <span class="s2">&quot;eV&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="n">efermi</span><span class="p">)</span><span class="o">.</span><span class="n">T</span><span class="p">[:,</span> <span class="n">idx_list</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]]</span><span class="o">.</span><span class="n">tolist</span><span class="p">()}</span>
            <span class="c1"># bz_kpoints = bz_kpoints[idx_list[:,1]].tolist()</span>

            <span class="n">sbs</span> <span class="o">=</span> <span class="n">BandStructureSymmLine</span><span class="p">(</span><span class="n">kpt_line</span><span class="p">,</span> <span class="n">bands_dict</span><span class="p">,</span>
                                        <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">reciprocal_lattice</span><span class="p">,</span>
                                        <span class="n">efermi</span><span class="p">,</span>
                                        <span class="n">labels_dict</span><span class="o">=</span><span class="n">labels_dict</span><span class="p">)</span>

            <span class="k">return</span> <span class="n">sbs</span>

        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">BoltztrapError</span><span class="p">(</span>
                <span class="s2">&quot;Bands are not in output of BoltzTraP.</span><span class="se">\n</span><span class="s2">BolztrapRunner must &quot;</span>
                <span class="s2">&quot;be run with run_type=BANDS&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.check_acc_bzt_bands"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.check_acc_bzt_bands">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">check_acc_bzt_bands</span><span class="p">(</span><span class="n">sbs_bz</span><span class="p">,</span> <span class="n">sbs_ref</span><span class="p">,</span> <span class="n">warn_thr</span><span class="o">=</span><span class="p">(</span><span class="mf">0.03</span><span class="p">,</span> <span class="mf">0.03</span><span class="p">)):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Compare sbs_bz BandStructureSymmLine calculated with boltztrap with</span>
<span class="sd">            the sbs_ref BandStructureSymmLine as reference (from MP for</span>
<span class="sd">            instance), computing correlation and energy difference for eight bands</span>
<span class="sd">            around the gap (semiconductors) or fermi level (metals).</span>
<span class="sd">            warn_thr is a threshold to get a warning in the accuracy of Boltztap</span>
<span class="sd">            interpolated bands.</span>
<span class="sd">            Return a dictionary with these keys:</span>
<span class="sd">            - &quot;N&quot;: the index of the band compared; inside each there are:</span>
<span class="sd">                - &quot;Corr&quot;: correlation coefficient for the 8 compared bands</span>
<span class="sd">                - &quot;Dist&quot;: energy distance for the 8 compared bands</span>
<span class="sd">                - &quot;branch_name&quot;: energy distance for that branch</span>
<span class="sd">            - &quot;avg_corr&quot;: average of correlation coefficient over the 8 bands</span>
<span class="sd">            - &quot;avg_dist&quot;: average of energy distance over the 8 bands</span>
<span class="sd">            - &quot;nb_list&quot;: list of indexes of the 8 compared bands</span>
<span class="sd">            - &quot;acc_thr&quot;: list of two float corresponing to the two warning</span>
<span class="sd">                         thresholds in input</span>
<span class="sd">            - &quot;acc_err&quot;: list of two bools:</span>
<span class="sd">                         True if the avg_corr &gt; warn_thr[0], and</span>
<span class="sd">                         True if the avg_dist &gt; warn_thr[1]</span>
<span class="sd">            See also compare_sym_bands function doc</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">sbs_ref</span><span class="o">.</span><span class="n">is_metal</span><span class="p">()</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">sbs_bz</span><span class="o">.</span><span class="n">is_metal</span><span class="p">():</span>
            <span class="n">vbm_idx</span> <span class="o">=</span> <span class="n">sbs_bz</span><span class="o">.</span><span class="n">get_vbm</span><span class="p">()[</span><span class="s1">&#39;band_index&#39;</span><span class="p">][</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">cbm_idx</span> <span class="o">=</span> <span class="n">sbs_bz</span><span class="o">.</span><span class="n">get_cbm</span><span class="p">()[</span><span class="s1">&#39;band_index&#39;</span><span class="p">][</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">nb_list</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="n">vbm_idx</span> <span class="o">-</span> <span class="mi">3</span><span class="p">,</span> <span class="n">cbm_idx</span> <span class="o">+</span> <span class="mi">4</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">bnd_around_efermi</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">delta</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">spin</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">sbs_bz</span><span class="o">.</span><span class="n">bands</span><span class="o">.</span><span class="n">keys</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">while</span> <span class="nb">len</span><span class="p">(</span><span class="n">bnd_around_efermi</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">8</span> <span class="ow">and</span> <span class="n">delta</span> <span class="o">&lt;</span> <span class="mi">100</span><span class="p">:</span>
                <span class="n">delta</span> <span class="o">+=</span> <span class="mf">0.1</span>
                <span class="n">bnd_around_efermi</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">nb</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">sbs_bz</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">spin</span><span class="p">])):</span>
                    <span class="k">for</span> <span class="n">kp</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">sbs_bz</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">nb</span><span class="p">])):</span>
                        <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">sbs_bz</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">nb</span><span class="p">][</span>
                                   <span class="n">kp</span><span class="p">]</span> <span class="o">-</span> <span class="n">sbs_bz</span><span class="o">.</span><span class="n">efermi</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">delta</span><span class="p">:</span>
                            <span class="n">bnd_around_efermi</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nb</span><span class="p">)</span>
                            <span class="k">break</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">bnd_around_efermi</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">8</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Warning! check performed on &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span>
                    <span class="nb">len</span><span class="p">(</span><span class="n">bnd_around_efermi</span><span class="p">)))</span>
                <span class="n">nb_list</span> <span class="o">=</span> <span class="n">bnd_around_efermi</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">nb_list</span> <span class="o">=</span> <span class="n">bnd_around_efermi</span><span class="p">[:</span><span class="mi">8</span><span class="p">]</span>

        <span class="c1"># print(nb_list)</span>
        <span class="n">bcheck</span> <span class="o">=</span> <span class="n">compare_sym_bands</span><span class="p">(</span><span class="n">sbs_bz</span><span class="p">,</span> <span class="n">sbs_ref</span><span class="p">,</span> <span class="n">nb_list</span><span class="p">)</span>
        <span class="c1"># print(bcheck)</span>
        <span class="n">acc_err</span> <span class="o">=</span> <span class="p">[</span><span class="kc">False</span><span class="p">,</span> <span class="kc">False</span><span class="p">]</span>
        <span class="n">avg_corr</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">([</span><span class="n">item</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="s1">&#39;Corr&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">bcheck</span><span class="o">.</span><span class="n">iteritems</span><span class="p">()])</span> <span class="o">/</span> <span class="mi">8</span>
        <span class="n">avg_distance</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">([</span><span class="n">item</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="s1">&#39;Dist&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">bcheck</span><span class="o">.</span><span class="n">iteritems</span><span class="p">()])</span> <span class="o">/</span> <span class="mi">8</span>

        <span class="k">if</span> <span class="n">avg_corr</span> <span class="o">&gt;</span> <span class="n">warn_thr</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
            <span class="n">acc_err</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="k">if</span> <span class="n">avg_distance</span> <span class="o">&gt;</span> <span class="n">warn_thr</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
            <span class="n">acc_err</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>

        <span class="n">bcheck</span><span class="p">[</span><span class="s1">&#39;avg_corr&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">avg_corr</span>
        <span class="n">bcheck</span><span class="p">[</span><span class="s1">&#39;avg_distance&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">avg_distance</span>
        <span class="n">bcheck</span><span class="p">[</span><span class="s1">&#39;acc_err&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">acc_err</span>
        <span class="n">bcheck</span><span class="p">[</span><span class="s1">&#39;acc_thr&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">warn_thr</span>
        <span class="n">bcheck</span><span class="p">[</span><span class="s1">&#39;nb_list&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">nb_list</span>

        <span class="k">if</span> <span class="kc">True</span> <span class="ow">in</span> <span class="n">acc_err</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Warning! some bands around gap are not accurate&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">bcheck</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.get_seebeck"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.get_seebeck">[docs]</a>    <span class="k">def</span> <span class="nf">get_seebeck</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="s1">&#39;eigs&#39;</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Gives the seebeck coefficient (microV/K) in either a</span>
<span class="sd">            full 3x3 tensor form, as 3 eigenvalues, or as the average value</span>
<span class="sd">            (trace/3.0) If doping_levels=True, the results are given at</span>
<span class="sd">            different p and n doping</span>
<span class="sd">            levels (given by self.doping), otherwise it is given as a series</span>
<span class="sd">            of electron chemical potential values</span>

<span class="sd">            Args:</span>
<span class="sd">                output (string): the type of output. &#39;tensor&#39; give the full</span>
<span class="sd">                3x3 tensor, &#39;eigs&#39; its 3 eigenvalues and</span>
<span class="sd">                &#39;average&#39; the average of the three eigenvalues</span>
<span class="sd">                doping_levels (boolean): True for the results to be given at</span>
<span class="sd">                different doping levels, False for results</span>
<span class="sd">                at different electron chemical potentials</span>

<span class="sd">            Returns:</span>
<span class="sd">                If doping_levels=True, a dictionary {temp:{&#39;p&#39;:[],&#39;n&#39;:[]}}.</span>
<span class="sd">                The &#39;p&#39; links to Seebeck at p-type doping</span>
<span class="sd">                and &#39;n&#39; to the Seebeck at n-type doping. Otherwise, returns a</span>
<span class="sd">                {temp:[]} dictionary</span>
<span class="sd">                The result contains either the sorted three eigenvalues of</span>
<span class="sd">                the symmetric</span>
<span class="sd">                Seebeck tensor (output=&#39;eigs&#39;) or a full tensor (3x3 array) (</span>
<span class="sd">                output=&#39;tensor&#39;) or as an average</span>
<span class="sd">                (output=&#39;average&#39;).</span>

<span class="sd">                units are microV/K</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">BoltztrapAnalyzer</span><span class="o">.</span><span class="n">_format_to_output</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_seebeck</span><span class="p">,</span>
                                                   <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span><span class="p">,</span>
                                                   <span class="n">output</span><span class="p">,</span>
                                                   <span class="n">doping_levels</span><span class="p">,</span> <span class="mf">1e6</span><span class="p">)</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.get_conductivity"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.get_conductivity">[docs]</a>    <span class="k">def</span> <span class="nf">get_conductivity</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="s1">&#39;eigs&#39;</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                         <span class="n">relaxation_time</span><span class="o">=</span><span class="mf">1e-14</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Gives the conductivity (1/Ohm*m) in either a full 3x3 tensor</span>
<span class="sd">            form, as 3 eigenvalues, or as the average value</span>
<span class="sd">            (trace/3.0) If doping_levels=True, the results are given at</span>
<span class="sd">            different p and n doping</span>
<span class="sd">            levels (given by self.doping), otherwise it is given as a series</span>
<span class="sd">            of electron chemical potential values</span>

<span class="sd">            Args:</span>
<span class="sd">                output (string): the type of output. &#39;tensor&#39; give the full</span>
<span class="sd">                3x3 tensor, &#39;eigs&#39; its 3 eigenvalues and</span>
<span class="sd">                &#39;average&#39; the average of the three eigenvalues</span>
<span class="sd">                doping_levels (boolean): True for the results to be given at</span>
<span class="sd">                different doping levels, False for results</span>
<span class="sd">                at different electron chemical potentials</span>
<span class="sd">                relaxation_time (float): constant relaxation time in secs</span>

<span class="sd">            Returns:</span>
<span class="sd">                If doping_levels=True, a dictionary {temp:{&#39;p&#39;:[],&#39;n&#39;:[]}}.</span>
<span class="sd">                The &#39;p&#39; links to conductivity</span>
<span class="sd">                at p-type doping and &#39;n&#39; to the conductivity at n-type</span>
<span class="sd">                doping. Otherwise,</span>
<span class="sd">                returns a {temp:[]} dictionary. The result contains either</span>
<span class="sd">                the sorted three eigenvalues of the symmetric</span>
<span class="sd">                conductivity tensor (format=&#39;eigs&#39;) or a full tensor (3x3</span>
<span class="sd">                array) (output=&#39;tensor&#39;) or as an average</span>
<span class="sd">                (output=&#39;average&#39;).</span>
<span class="sd">                The result includes a given constant relaxation time</span>

<span class="sd">                units are 1/Ohm*m</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">BoltztrapAnalyzer</span><span class="o">.</span><span class="n">_format_to_output</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cond</span><span class="p">,</span>
                                                   <span class="bp">self</span><span class="o">.</span><span class="n">_cond_doping</span><span class="p">,</span> <span class="n">output</span><span class="p">,</span>
                                                   <span class="n">doping_levels</span><span class="p">,</span>
                                                   <span class="n">relaxation_time</span><span class="p">)</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.get_power_factor"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.get_power_factor">[docs]</a>    <span class="k">def</span> <span class="nf">get_power_factor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="s1">&#39;eigs&#39;</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                         <span class="n">relaxation_time</span><span class="o">=</span><span class="mf">1e-14</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gives the power factor (Seebeck^2 * conductivity) in units</span>
<span class="sd">        microW/(m*K^2) in either a full 3x3 tensor form,</span>
<span class="sd">        as 3 eigenvalues, or as the average value (trace/3.0) If</span>
<span class="sd">        doping_levels=True, the results are given at</span>
<span class="sd">        different p and n doping levels (given by self.doping), otherwise it</span>
<span class="sd">        is given as a series of</span>
<span class="sd">        electron chemical potential values</span>

<span class="sd">        Args:</span>
<span class="sd">            output (string): the type of output. &#39;tensor&#39; give the full 3x3</span>
<span class="sd">            tensor, &#39;eigs&#39; its 3 eigenvalues and</span>
<span class="sd">            &#39;average&#39; the average of the three eigenvalues</span>
<span class="sd">            doping_levels (boolean): True for the results to be given at</span>
<span class="sd">            different doping levels, False for results</span>
<span class="sd">            at different electron chemical potentials</span>
<span class="sd">            relaxation_time (float): constant relaxation time in secs</span>

<span class="sd">        Returns:</span>
<span class="sd">            If doping_levels=True, a dictionnary {temp:{&#39;p&#39;:[],&#39;n&#39;:[]}}. The</span>
<span class="sd">            &#39;p&#39; links to power factor</span>
<span class="sd">            at p-type doping and &#39;n&#39; to the conductivity at n-type doping.</span>
<span class="sd">            Otherwise,</span>
<span class="sd">            returns a {temp:[]} dictionary. The result contains either the</span>
<span class="sd">            sorted three eigenvalues of the symmetric</span>
<span class="sd">            power factor tensor (format=&#39;eigs&#39;) or a full tensor (3x3 array) (</span>
<span class="sd">            output=&#39;tensor&#39;) or as an average</span>
<span class="sd">            (output=&#39;average&#39;).</span>
<span class="sd">            The result includes a given constant relaxation time</span>

<span class="sd">            units are microW/(m K^2)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">result_doping</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">doping_levels</span><span class="p">:</span>
            <span class="n">result_doping</span> <span class="o">=</span> <span class="p">{</span><span class="n">doping</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span>
                                      <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">]}</span> <span class="k">for</span>
                             <span class="n">doping</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span><span class="p">}</span>

            <span class="k">for</span> <span class="n">doping</span> <span class="ow">in</span> <span class="n">result_doping</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">result_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">]:</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="p">[</span><span class="n">doping</span><span class="p">])):</span>
                        <span class="n">full_tensor</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cond_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                                             <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span>
                                                 <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span>
                                                     <span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                                                 <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span>
                                                     <span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span>
                        <span class="n">result_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">t</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">full_tensor</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">result</span> <span class="o">=</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck</span><span class="p">}</span>
            <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">result</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mu_steps</span><span class="p">)):</span>
                    <span class="n">full_tensor</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cond</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                                         <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_seebeck</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                                                <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span>
                    <span class="n">result</span><span class="p">[</span><span class="n">t</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">full_tensor</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">BoltztrapAnalyzer</span><span class="o">.</span><span class="n">_format_to_output</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">result_doping</span><span class="p">,</span>
                                                   <span class="n">output</span><span class="p">,</span> <span class="n">doping_levels</span><span class="p">,</span>
                                                   <span class="n">multi</span><span class="o">=</span><span class="mf">1e6</span> <span class="o">*</span> <span class="n">relaxation_time</span><span class="p">)</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.get_thermal_conductivity"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.get_thermal_conductivity">[docs]</a>    <span class="k">def</span> <span class="nf">get_thermal_conductivity</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="s1">&#39;eigs&#39;</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                 <span class="n">k_el</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">relaxation_time</span><span class="o">=</span><span class="mf">1e-14</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gives the electronic part of the thermal conductivity in either a</span>
<span class="sd">        full 3x3 tensor form,</span>
<span class="sd">        as 3 eigenvalues, or as the average value (trace/3.0) If</span>
<span class="sd">        doping_levels=True, the results are given at</span>
<span class="sd">        different p and n doping levels (given by self.doping), otherwise it</span>
<span class="sd">        is given as a series of</span>
<span class="sd">        electron chemical potential values</span>

<span class="sd">        Args:</span>
<span class="sd">            output (string): the type of output. &#39;tensor&#39; give the full 3x3</span>
<span class="sd">            tensor, &#39;eigs&#39; its 3 eigenvalues and</span>
<span class="sd">            &#39;average&#39; the average of the three eigenvalues</span>
<span class="sd">            doping_levels (boolean): True for the results to be given at</span>
<span class="sd">            different doping levels, False for results</span>
<span class="sd">            at different electron chemical potentials</span>
<span class="sd">            k_el (boolean): True for k_0-PF*T, False for k_0</span>
<span class="sd">            relaxation_time (float): constant relaxation time in secs</span>

<span class="sd">        Returns:</span>
<span class="sd">            If doping_levels=True, a dictionary {temp:{&#39;p&#39;:[],&#39;n&#39;:[]}}. The</span>
<span class="sd">            &#39;p&#39; links to thermal conductivity</span>
<span class="sd">            at p-type doping and &#39;n&#39; to the thermal conductivity at n-type</span>
<span class="sd">            doping. Otherwise,</span>
<span class="sd">            returns a {temp:[]} dictionary. The result contains either the</span>
<span class="sd">            sorted three eigenvalues of the symmetric</span>
<span class="sd">            conductivity tensor (format=&#39;eigs&#39;) or a full tensor (3x3 array) (</span>
<span class="sd">            output=&#39;tensor&#39;) or as an average</span>
<span class="sd">            (output=&#39;average&#39;).</span>
<span class="sd">            The result includes a given constant relaxation time</span>

<span class="sd">            units are W/mK</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">result_doping</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">doping_levels</span><span class="p">:</span>
            <span class="n">result_doping</span> <span class="o">=</span> <span class="p">{</span><span class="n">doping</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span>
                                      <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">]}</span> <span class="k">for</span>
                             <span class="n">doping</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span><span class="p">}</span>
            <span class="k">for</span> <span class="n">doping</span> <span class="ow">in</span> <span class="n">result_doping</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">result_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">]:</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="p">[</span><span class="n">doping</span><span class="p">])):</span>
                        <span class="k">if</span> <span class="n">k_el</span><span class="p">:</span>
                            <span class="n">pf_tensor</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cond_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                                               <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span>
                                                   <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span>
                                                       <span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                                                   <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span>
                                                       <span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span>
                            <span class="n">result_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">t</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">((</span>
                                    <span class="bp">self</span><span class="o">.</span><span class="n">_kappa_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">t</span><span class="p">][</span>
                                        <span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="n">pf_tensor</span> <span class="o">*</span> <span class="n">t</span><span class="p">))</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="n">result_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">t</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">((</span>
                                <span class="bp">self</span><span class="o">.</span><span class="n">_kappa_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">result</span> <span class="o">=</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck</span><span class="p">}</span>
            <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">result</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mu_steps</span><span class="p">)):</span>
                    <span class="k">if</span> <span class="n">k_el</span><span class="p">:</span>
                        <span class="n">pf_tensor</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cond</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                                           <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_seebeck</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                                                  <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span>
                        <span class="n">result</span><span class="p">[</span><span class="n">t</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">_kappa</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="n">pf_tensor</span> <span class="o">*</span> <span class="n">t</span><span class="p">))</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">result</span><span class="p">[</span><span class="n">t</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">_kappa</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span>

        <span class="k">return</span> <span class="n">BoltztrapAnalyzer</span><span class="o">.</span><span class="n">_format_to_output</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">result_doping</span><span class="p">,</span>
                                                   <span class="n">output</span><span class="p">,</span> <span class="n">doping_levels</span><span class="p">,</span>
                                                   <span class="n">multi</span><span class="o">=</span><span class="n">relaxation_time</span><span class="p">)</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.get_zt"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.get_zt">[docs]</a>    <span class="k">def</span> <span class="nf">get_zt</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="s1">&#39;eigs&#39;</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">relaxation_time</span><span class="o">=</span><span class="mf">1e-14</span><span class="p">,</span>
               <span class="n">kl</span><span class="o">=</span><span class="mf">1.0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gives the ZT coefficient (S^2*cond*T/thermal cond) in either a full</span>
<span class="sd">        3x3 tensor form,</span>
<span class="sd">        as 3 eigenvalues, or as the average value (trace/3.0) If</span>
<span class="sd">        doping_levels=True, the results are given at</span>
<span class="sd">        different p and n doping levels (given by self.doping), otherwise it</span>
<span class="sd">        is given as a series of</span>
<span class="sd">        electron chemical potential values. We assume a constant relaxation</span>
<span class="sd">        time and a constant</span>
<span class="sd">        lattice thermal conductivity</span>

<span class="sd">        Args:</span>
<span class="sd">            output (string): the type of output. &#39;tensor&#39; give the full 3x3</span>
<span class="sd">            tensor, &#39;eigs&#39; its 3 eigenvalues and</span>
<span class="sd">            &#39;average&#39; the average of the three eigenvalues</span>
<span class="sd">            doping_levels (boolean): True for the results to be given at</span>
<span class="sd">            different doping levels, False for results</span>
<span class="sd">            at different electron chemical potentials</span>
<span class="sd">            relaxation_time (float): constant relaxation time in secs</span>
<span class="sd">            k_l (float): lattice thermal cond in W/(m*K)</span>

<span class="sd">        Returns:</span>
<span class="sd">            If doping_levels=True, a dictionary {temp:{&#39;p&#39;:[],&#39;n&#39;:[]}}. The</span>
<span class="sd">            &#39;p&#39; links to ZT</span>
<span class="sd">            at p-type doping and &#39;n&#39; to the ZT at n-type doping. Otherwise,</span>
<span class="sd">            returns a {temp:[]} dictionary. The result contains either the</span>
<span class="sd">            sorted three eigenvalues of the symmetric</span>
<span class="sd">            ZT tensor (format=&#39;eigs&#39;) or a full tensor (3x3 array) (</span>
<span class="sd">            output=&#39;tensor&#39;) or as an average</span>
<span class="sd">            (output=&#39;average&#39;).</span>
<span class="sd">            The result includes a given constant relaxation time and lattice</span>
<span class="sd">            thermal conductivity</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">result_doping</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">doping_levels</span><span class="p">:</span>
            <span class="n">result_doping</span> <span class="o">=</span> <span class="p">{</span><span class="n">doping</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span>
                                      <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">]}</span> <span class="k">for</span>
                             <span class="n">doping</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span><span class="p">}</span>

            <span class="k">for</span> <span class="n">doping</span> <span class="ow">in</span> <span class="n">result_doping</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">result_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">]:</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="p">[</span><span class="n">doping</span><span class="p">])):</span>
                        <span class="n">pf_tensor</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cond_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                                           <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span>
                                               <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">t</span><span class="p">][</span>
                                                   <span class="n">i</span><span class="p">],</span>
                                               <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">t</span><span class="p">][</span>
                                                   <span class="n">i</span><span class="p">]))</span>
                        <span class="n">thermal_conduct</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_kappa_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
                                           <span class="o">-</span> <span class="n">pf_tensor</span> <span class="o">*</span> <span class="n">t</span><span class="p">)</span> <span class="o">*</span> <span class="n">relaxation_time</span>
                        <span class="n">result_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">t</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                            <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">pf_tensor</span> <span class="o">*</span> <span class="n">relaxation_time</span> <span class="o">*</span> <span class="n">t</span><span class="p">,</span>
                                   <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span>
                                       <span class="n">thermal_conduct</span> <span class="o">+</span> <span class="n">kl</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">result</span> <span class="o">=</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck</span><span class="p">}</span>
            <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">result</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mu_steps</span><span class="p">)):</span>
                    <span class="n">pf_tensor</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cond</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                                       <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_seebeck</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                                              <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span>
                    <span class="n">thermal_conduct</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_kappa</span><span class="p">[</span><span class="n">t</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
                                       <span class="o">-</span> <span class="n">pf_tensor</span> <span class="o">*</span> <span class="n">t</span><span class="p">)</span> <span class="o">*</span> <span class="n">relaxation_time</span>
                    <span class="n">result</span><span class="p">[</span><span class="n">t</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">pf_tensor</span> <span class="o">*</span> <span class="n">relaxation_time</span> <span class="o">*</span> <span class="n">t</span><span class="p">,</span>
                                            <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span>
                                                <span class="n">thermal_conduct</span> <span class="o">+</span> <span class="n">kl</span> <span class="o">*</span>
                                                <span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))))</span>

        <span class="k">return</span> <span class="n">BoltztrapAnalyzer</span><span class="o">.</span><span class="n">_format_to_output</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">result_doping</span><span class="p">,</span>
                                                   <span class="n">output</span><span class="p">,</span> <span class="n">doping_levels</span><span class="p">)</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.get_average_eff_mass"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.get_average_eff_mass">[docs]</a>    <span class="k">def</span> <span class="nf">get_average_eff_mass</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="s1">&#39;eigs&#39;</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gives the average effective mass tensor. We call it average because</span>
<span class="sd">        it takes into account all the bands</span>
<span class="sd">        and regions in the Brillouin zone. This is different than the standard</span>
<span class="sd">        textbook effective mass which relates</span>
<span class="sd">        often to only one (parabolic) band.</span>
<span class="sd">        The average effective mass tensor is defined as the integrated</span>
<span class="sd">        average of the second derivative of E(k)</span>
<span class="sd">        This effective mass tensor takes into account:</span>
<span class="sd">        -non-parabolicity</span>
<span class="sd">        -multiple extrema</span>
<span class="sd">        -multiple bands</span>

<span class="sd">        For more information about it. See:</span>

<span class="sd">        Hautier, G., Miglio, A., Waroquiers, D., Rignanese, G., &amp; Gonze,</span>
<span class="sd">        X. (2014).</span>
<span class="sd">        How Does Chemistry Influence Electron Effective Mass in Oxides?</span>
<span class="sd">        A High-Throughput Computational Analysis. Chemistry of Materials,</span>
<span class="sd">        26(19), 5447–5458. doi:10.1021/cm404079a</span>

<span class="sd">        or</span>

<span class="sd">        Hautier, G., Miglio, A., Ceder, G., Rignanese, G.-M., &amp; Gonze,</span>
<span class="sd">        X. (2013).</span>
<span class="sd">        Identification and design principles of low hole effective mass</span>
<span class="sd">        p-type transparent conducting oxides.</span>
<span class="sd">        Nature Communications, 4, 2292. doi:10.1038/ncomms3292</span>

<span class="sd">        Depending on the value of output, we have either the full 3x3</span>
<span class="sd">        effective mass tensor,</span>
<span class="sd">        its 3 eigenvalues or an average</span>

<span class="sd">        Args:</span>
<span class="sd">            output (string): &#39;eigs&#39; for eigenvalues, &#39;tensor&#39; for the full</span>
<span class="sd">            tensor and &#39;average&#39; for an average (trace/3)</span>
<span class="sd">            doping_levels (boolean): True for the results to be given at</span>
<span class="sd">            different doping levels, False for results</span>
<span class="sd">            at different electron chemical potentials</span>
<span class="sd">        Returns:</span>
<span class="sd">            If doping_levels=True,a dictionary {&#39;p&#39;:{temp:[]},&#39;n&#39;:{temp:[]}}</span>
<span class="sd">            with an array of effective mass tensor, eigenvalues of average</span>
<span class="sd">            value (depending on output) for each temperature and for each</span>
<span class="sd">            doping level.</span>
<span class="sd">            The &#39;p&#39; links to hole effective mass tensor and &#39;n&#39; to electron</span>
<span class="sd">            effective mass tensor.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">result_doping</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">conc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_carrier_concentration</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">doping_levels</span><span class="p">:</span>
            <span class="n">result_doping</span> <span class="o">=</span> <span class="p">{</span><span class="n">doping</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cond_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">]}</span>
                             <span class="k">for</span>
                             <span class="n">doping</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="p">}</span>
            <span class="k">for</span> <span class="n">doping</span> <span class="ow">in</span> <span class="n">result_doping</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">temp</span> <span class="ow">in</span> <span class="n">result_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">]:</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="p">[</span><span class="n">doping</span><span class="p">])):</span>
                        <span class="k">try</span><span class="p">:</span>
                            <span class="n">result_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span>
                                <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cond_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">temp</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="mi">10</span> <span class="o">**</span> <span class="mi">6</span> <span class="o">*</span>
                                         <span class="n">constants</span><span class="o">.</span><span class="n">e</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">/</span> <span class="n">constants</span><span class="o">.</span><span class="n">m_e</span><span class="p">)</span>
                        <span class="k">except</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">LinAlgError</span><span class="p">:</span>
                            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">result</span> <span class="o">=</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck</span><span class="p">}</span>
            <span class="k">for</span> <span class="n">temp</span> <span class="ow">in</span> <span class="n">result</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mu_steps</span><span class="p">)):</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="n">cond_inv</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cond</span><span class="p">[</span><span class="n">temp</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span>
                    <span class="k">except</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">LinAlgError</span><span class="p">:</span>
                        <span class="k">pass</span>
                    <span class="n">result</span><span class="p">[</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cond_inv</span> <span class="o">*</span> <span class="n">conc</span><span class="p">[</span><span class="n">temp</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="mi">10</span> <span class="o">**</span> <span class="mi">6</span> <span class="o">*</span> <span class="n">constants</span><span class="o">.</span><span class="n">e</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">/</span> <span class="n">constants</span><span class="o">.</span><span class="n">m_e</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">BoltztrapAnalyzer</span><span class="o">.</span><span class="n">_format_to_output</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">result_doping</span><span class="p">,</span>
                                                   <span class="n">output</span><span class="p">,</span> <span class="n">doping_levels</span><span class="p">)</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.get_seebeck_eff_mass"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.get_seebeck_eff_mass">[docs]</a>    <span class="k">def</span> <span class="nf">get_seebeck_eff_mass</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="s1">&#39;average&#39;</span><span class="p">,</span> <span class="n">temp</span><span class="o">=</span><span class="mi">300</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                             <span class="n">Lambda</span><span class="o">=</span><span class="mf">0.5</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Seebeck effective mass calculated as explained in Ref.</span>
<span class="sd">        Gibbs, Z. M. et al., Effective mass and fermi surface complexity factor</span>
<span class="sd">        from ab initio band structure calculations.</span>
<span class="sd">        npj Computational Materials 3, 8 (2017).</span>

<span class="sd">        Args:</span>
<span class="sd">            output: &#39;average&#39; returns the seebeck effective mass calculated using</span>
<span class="sd">                    the average of the three diagonal components of the seebeck tensor.</span>
<span class="sd">                    &#39;tensor&#39; returns the seebeck effective mass respect to the three</span>
<span class="sd">                    diagonal components of the seebeck tensor.</span>
<span class="sd">            doping_levels: False means that the seebeck effective mass is calculated</span>
<span class="sd">                           for every value of the chemical potential</span>
<span class="sd">                           True means that the seebeck effective mass is calculated</span>
<span class="sd">                           for every value of the doping levels for both n and p types</span>
<span class="sd">            temp:   temperature of calculated seebeck.</span>
<span class="sd">            Lambda: fitting parameter used to model the scattering (0.5 means constant</span>
<span class="sd">                    relaxation time).</span>
<span class="sd">        Returns:</span>
<span class="sd">            a list of values for the seebeck effective mass w.r.t the chemical potential,</span>
<span class="sd">            if doping_levels is set at False;</span>
<span class="sd">            a dict with n an p keys that contain a list of values for the seebeck effective</span>
<span class="sd">            mass w.r.t the doping levels, if doping_levels is set at True;</span>
<span class="sd">            if &#39;tensor&#39; is selected, each element of the lists is a list containing</span>
<span class="sd">            the three components of the seebeck effective mass.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">doping_levels</span><span class="p">:</span>
            <span class="n">sbk_mass</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="s1">&#39;p&#39;</span><span class="p">):</span>
                <span class="n">conc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="p">[</span><span class="n">dt</span><span class="p">]</span>
                <span class="n">seebeck</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_seebeck</span><span class="p">(</span><span class="n">output</span><span class="o">=</span><span class="n">output</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">True</span><span class="p">)[</span><span class="n">dt</span><span class="p">][</span><span class="n">temp</span><span class="p">]</span>
                <span class="n">sbk_mass</span><span class="p">[</span><span class="n">dt</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">conc</span><span class="p">)):</span>
                    <span class="k">if</span> <span class="n">output</span> <span class="o">==</span> <span class="s1">&#39;average&#39;</span><span class="p">:</span>
                        <span class="n">sbk_mass</span><span class="p">[</span><span class="n">dt</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                            <span class="n">seebeck_eff_mass_from_seebeck_carr</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">seebeck</span><span class="p">[</span><span class="n">i</span><span class="p">]),</span>
                                                               <span class="n">conc</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">temp</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">))</span>
                    <span class="k">elif</span> <span class="n">output</span> <span class="o">==</span> <span class="s1">&#39;tensor&#39;</span><span class="p">:</span>
                        <span class="n">sbk_mass</span><span class="p">[</span><span class="n">dt</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">([])</span>
                        <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
                            <span class="n">sbk_mass</span><span class="p">[</span><span class="n">dt</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                                <span class="n">seebeck_eff_mass_from_seebeck_carr</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">seebeck</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">j</span><span class="p">]),</span>
                                                                   <span class="n">conc</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">temp</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">))</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">seebeck</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_seebeck</span><span class="p">(</span><span class="n">output</span><span class="o">=</span><span class="n">output</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">False</span><span class="p">)[</span><span class="n">temp</span><span class="p">]</span>
            <span class="n">conc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_carrier_concentration</span><span class="p">()[</span><span class="n">temp</span><span class="p">]</span>
            <span class="n">sbk_mass</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">conc</span><span class="p">)):</span>
                <span class="k">if</span> <span class="n">output</span> <span class="o">==</span> <span class="s1">&#39;average&#39;</span><span class="p">:</span>
                    <span class="n">sbk_mass</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                        <span class="n">seebeck_eff_mass_from_seebeck_carr</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">seebeck</span><span class="p">[</span><span class="n">i</span><span class="p">]),</span>
                                                           <span class="n">conc</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">temp</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">))</span>
                <span class="k">elif</span> <span class="n">output</span> <span class="o">==</span> <span class="s1">&#39;tensor&#39;</span><span class="p">:</span>
                    <span class="n">sbk_mass</span><span class="o">.</span><span class="n">append</span><span class="p">([])</span>
                    <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
                        <span class="n">sbk_mass</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                            <span class="n">seebeck_eff_mass_from_seebeck_carr</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">seebeck</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">j</span><span class="p">]),</span>
                                                               <span class="n">conc</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">temp</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">sbk_mass</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.get_complexity_factor"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.get_complexity_factor">[docs]</a>    <span class="k">def</span> <span class="nf">get_complexity_factor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="s1">&#39;average&#39;</span><span class="p">,</span> <span class="n">temp</span><span class="o">=</span><span class="mi">300</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                              <span class="n">Lambda</span><span class="o">=</span><span class="mf">0.5</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Fermi surface complexity factor respect to calculated as explained in Ref.</span>
<span class="sd">        Gibbs, Z. M. et al., Effective mass and fermi surface complexity factor</span>
<span class="sd">        from ab initio band structure calculations.</span>
<span class="sd">        npj Computational Materials 3, 8 (2017).</span>

<span class="sd">        Args:</span>
<span class="sd">            output: &#39;average&#39; returns the complexity factor calculated using the average</span>
<span class="sd">                    of the three diagonal components of the seebeck and conductivity tensors.</span>
<span class="sd">                    &#39;tensor&#39; returns the complexity factor respect to the three</span>
<span class="sd">                    diagonal components of seebeck and conductivity tensors.</span>
<span class="sd">            doping_levels: False means that the complexity factor is calculated</span>
<span class="sd">                           for every value of the chemical potential</span>
<span class="sd">                           True means that the complexity factor is calculated</span>
<span class="sd">                           for every value of the doping levels for both n and p types</span>
<span class="sd">            temp:   temperature of calculated seebeck and conductivity.</span>
<span class="sd">            Lambda: fitting parameter used to model the scattering (0.5 means constant</span>
<span class="sd">                    relaxation time).</span>
<span class="sd">        Returns:</span>
<span class="sd">            a list of values for the complexity factor w.r.t the chemical potential,</span>
<span class="sd">            if doping_levels is set at False;</span>
<span class="sd">            a dict with n an p keys that contain a list of values for the complexity factor</span>
<span class="sd">            w.r.t the doping levels, if doping_levels is set at True;</span>
<span class="sd">            if &#39;tensor&#39; is selected, each element of the lists is a list containing</span>
<span class="sd">            the three components of the complexity factor.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">doping_levels</span><span class="p">:</span>
            <span class="n">cmplx_fact</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="s1">&#39;p&#39;</span><span class="p">):</span>
                <span class="n">sbk_mass</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_seebeck_eff_mass</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">temp</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">)[</span><span class="n">dt</span><span class="p">]</span>
                <span class="n">cond_mass</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_average_eff_mass</span><span class="p">(</span><span class="n">output</span><span class="o">=</span><span class="n">output</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">True</span><span class="p">)[</span><span class="n">dt</span><span class="p">][</span><span class="n">temp</span><span class="p">]</span>

                <span class="k">if</span> <span class="n">output</span> <span class="o">==</span> <span class="s1">&#39;average&#39;</span><span class="p">:</span>
                    <span class="n">cmplx_fact</span><span class="p">[</span><span class="n">dt</span><span class="p">]</span> <span class="o">=</span> <span class="p">[(</span><span class="n">m_s</span> <span class="o">/</span> <span class="nb">abs</span><span class="p">(</span><span class="n">m_c</span><span class="p">))</span> <span class="o">**</span> <span class="mf">1.5</span> <span class="k">for</span> <span class="n">m_s</span><span class="p">,</span> <span class="n">m_c</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">sbk_mass</span><span class="p">,</span> <span class="n">cond_mass</span><span class="p">)]</span>
                <span class="k">elif</span> <span class="n">output</span> <span class="o">==</span> <span class="s1">&#39;tensor&#39;</span><span class="p">:</span>
                    <span class="n">cmplx_fact</span><span class="p">[</span><span class="n">dt</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">sbk_mass</span><span class="p">)):</span>
                        <span class="n">cmplx_fact</span><span class="p">[</span><span class="n">dt</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">([])</span>
                        <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
                            <span class="n">cmplx_fact</span><span class="p">[</span><span class="n">dt</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">sbk_mass</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">/</span> <span class="nb">abs</span><span class="p">(</span><span class="n">cond_mass</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">j</span><span class="p">]))</span> <span class="o">**</span> <span class="mf">1.5</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">sbk_mass</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_seebeck_eff_mass</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">temp</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">)</span>
            <span class="n">cond_mass</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_average_eff_mass</span><span class="p">(</span><span class="n">output</span><span class="o">=</span><span class="n">output</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">False</span><span class="p">)[</span><span class="n">temp</span><span class="p">]</span>

            <span class="k">if</span> <span class="n">output</span> <span class="o">==</span> <span class="s1">&#39;average&#39;</span><span class="p">:</span>
                <span class="n">cmplx_fact</span> <span class="o">=</span> <span class="p">[(</span><span class="n">m_s</span> <span class="o">/</span> <span class="nb">abs</span><span class="p">(</span><span class="n">m_c</span><span class="p">))</span> <span class="o">**</span> <span class="mf">1.5</span> <span class="k">for</span> <span class="n">m_s</span><span class="p">,</span> <span class="n">m_c</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">sbk_mass</span><span class="p">,</span> <span class="n">cond_mass</span><span class="p">)]</span>
            <span class="k">elif</span> <span class="n">output</span> <span class="o">==</span> <span class="s1">&#39;tensor&#39;</span><span class="p">:</span>
                <span class="n">cmplx_fact</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">sbk_mass</span><span class="p">)):</span>
                    <span class="n">cmplx_fact</span><span class="o">.</span><span class="n">append</span><span class="p">([])</span>
                    <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
                        <span class="n">cmplx_fact</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">sbk_mass</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">/</span> <span class="nb">abs</span><span class="p">(</span><span class="n">cond_mass</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">j</span><span class="p">]))</span> <span class="o">**</span> <span class="mf">1.5</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">cmplx_fact</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.get_extreme"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.get_extreme">[docs]</a>    <span class="k">def</span> <span class="nf">get_extreme</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">target_prop</span><span class="p">,</span> <span class="n">maximize</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">min_temp</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                    <span class="n">max_temp</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">min_doping</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">max_doping</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                    <span class="n">isotropy_tolerance</span><span class="o">=</span><span class="mf">0.05</span><span class="p">,</span> <span class="n">use_average</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        This method takes in eigenvalues over a range of carriers,</span>
<span class="sd">        temperatures, and doping levels, and tells you what is the &quot;best&quot;</span>
<span class="sd">        value that can be achieved for the given target_property. Note that</span>
<span class="sd">        this method searches the doping dict only, not the full mu dict.</span>

<span class="sd">        Args:</span>
<span class="sd">            target_prop: target property, i.e. &quot;seebeck&quot;, &quot;power factor&quot;,</span>
<span class="sd">                         &quot;conductivity&quot;, &quot;kappa&quot;, or &quot;zt&quot;</span>
<span class="sd">            maximize: True to maximize, False to minimize (e.g. kappa)</span>
<span class="sd">            min_temp: minimum temperature allowed</span>
<span class="sd">            max_temp: maximum temperature allowed</span>
<span class="sd">            min_doping: minimum doping allowed (e.g., 1E18)</span>
<span class="sd">            max_doping: maximum doping allowed (e.g., 1E20)</span>
<span class="sd">            isotropy_tolerance: tolerance for isotropic (0.05 = 5%)</span>
<span class="sd">            use_average: True for avg of eigenval, False for max eigenval</span>

<span class="sd">        Returns:</span>
<span class="sd">            A dictionary with keys {&quot;p&quot;, &quot;n&quot;, &quot;best&quot;} with sub-keys:</span>
<span class="sd">            {&quot;value&quot;, &quot;temperature&quot;, &quot;doping&quot;, &quot;isotropic&quot;}</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">def</span> <span class="nf">is_isotropic</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">isotropy_tolerance</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Internal method to tell you if 3-vector &quot;x&quot; is isotropic</span>

<span class="sd">            Args:</span>
<span class="sd">                x: the vector to determine isotropy for</span>
<span class="sd">                isotropy_tolerance: tolerance, e.g. 0.05 is 5%</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">3</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid input to is_isotropic!&quot;</span><span class="p">)</span>

            <span class="n">st</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
            <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="nb">all</span><span class="p">([</span><span class="n">st</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">st</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">st</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span> <span class="ow">and</span>
                        <span class="p">(</span><span class="nb">abs</span><span class="p">((</span><span class="n">st</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">st</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">/</span> <span class="n">st</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">&lt;=</span> <span class="n">isotropy_tolerance</span><span class="p">)</span> <span class="ow">and</span>
                        <span class="p">(</span><span class="nb">abs</span><span class="p">((</span><span class="n">st</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="n">st</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span> <span class="o">/</span> <span class="n">st</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">isotropy_tolerance</span><span class="p">)</span> <span class="ow">and</span>
                        <span class="p">(</span><span class="nb">abs</span><span class="p">((</span><span class="n">st</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="n">st</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">/</span> <span class="n">st</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">&lt;=</span> <span class="n">isotropy_tolerance</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">target_prop</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s2">&quot;seebeck&quot;</span><span class="p">:</span>
            <span class="n">d</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_seebeck</span><span class="p">(</span><span class="n">output</span><span class="o">=</span><span class="s2">&quot;eigs&quot;</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="k">elif</span> <span class="n">target_prop</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s2">&quot;power factor&quot;</span><span class="p">:</span>
            <span class="n">d</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_power_factor</span><span class="p">(</span><span class="n">output</span><span class="o">=</span><span class="s2">&quot;eigs&quot;</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="k">elif</span> <span class="n">target_prop</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s2">&quot;conductivity&quot;</span><span class="p">:</span>
            <span class="n">d</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_conductivity</span><span class="p">(</span><span class="n">output</span><span class="o">=</span><span class="s2">&quot;eigs&quot;</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="k">elif</span> <span class="n">target_prop</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s2">&quot;kappa&quot;</span><span class="p">:</span>
            <span class="n">d</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_thermal_conductivity</span><span class="p">(</span><span class="n">output</span><span class="o">=</span><span class="s2">&quot;eigs&quot;</span><span class="p">,</span>
                                              <span class="n">doping_levels</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">target_prop</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s2">&quot;zt&quot;</span><span class="p">:</span>
            <span class="n">d</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_zt</span><span class="p">(</span><span class="n">output</span><span class="o">=</span><span class="s2">&quot;eigs&quot;</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Target property: </span><span class="si">{}</span><span class="s2"> not recognized!&quot;</span><span class="o">.</span>
                             <span class="nb">format</span><span class="p">(</span><span class="n">target_prop</span><span class="p">))</span>

        <span class="n">absval</span> <span class="o">=</span> <span class="kc">True</span>  <span class="c1"># take the absolute value of properties</span>

        <span class="n">x_val</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">x_temp</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">x_doping</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">x_isotropic</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">output</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="n">min_temp</span> <span class="o">=</span> <span class="n">min_temp</span> <span class="ow">or</span> <span class="mi">0</span>
        <span class="n">max_temp</span> <span class="o">=</span> <span class="n">max_temp</span> <span class="ow">or</span> <span class="nb">float</span><span class="p">(</span><span class="s1">&#39;inf&#39;</span><span class="p">)</span>
        <span class="n">min_doping</span> <span class="o">=</span> <span class="n">min_doping</span> <span class="ow">or</span> <span class="mi">0</span>
        <span class="n">max_doping</span> <span class="o">=</span> <span class="n">max_doping</span> <span class="ow">or</span> <span class="nb">float</span><span class="p">(</span><span class="s1">&#39;inf&#39;</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">pn</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;p&#39;</span><span class="p">,</span> <span class="s1">&#39;n&#39;</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="n">pn</span><span class="p">]:</span>  <span class="c1"># temperatures</span>
                <span class="k">if</span> <span class="n">min_temp</span> <span class="o">&lt;=</span> <span class="nb">float</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="n">max_temp</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">didx</span><span class="p">,</span> <span class="n">evs</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">pn</span><span class="p">][</span><span class="n">t</span><span class="p">]):</span>
                        <span class="n">doping_lvl</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="p">[</span><span class="n">pn</span><span class="p">][</span><span class="n">didx</span><span class="p">]</span>
                        <span class="k">if</span> <span class="n">min_doping</span> <span class="o">&lt;=</span> <span class="n">doping_lvl</span> <span class="o">&lt;=</span> <span class="n">max_doping</span><span class="p">:</span>
                            <span class="n">isotropic</span> <span class="o">=</span> <span class="n">is_isotropic</span><span class="p">(</span><span class="n">evs</span><span class="p">,</span> <span class="n">isotropy_tolerance</span><span class="p">)</span>
                            <span class="k">if</span> <span class="n">absval</span><span class="p">:</span>
                                <span class="n">evs</span> <span class="o">=</span> <span class="p">[</span><span class="nb">abs</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">evs</span><span class="p">]</span>
                            <span class="k">if</span> <span class="n">use_average</span><span class="p">:</span>
                                <span class="n">val</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="nb">sum</span><span class="p">(</span><span class="n">evs</span><span class="p">))</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">evs</span><span class="p">)</span>
                            <span class="k">else</span><span class="p">:</span>
                                <span class="n">val</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">evs</span><span class="p">)</span>
                            <span class="k">if</span> <span class="n">x_val</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="p">(</span><span class="n">val</span> <span class="o">&gt;</span> <span class="n">x_val</span> <span class="ow">and</span> <span class="n">maximize</span><span class="p">)</span> \
                                    <span class="ow">or</span> <span class="p">(</span><span class="n">val</span> <span class="o">&lt;</span> <span class="n">x_val</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">maximize</span><span class="p">):</span>
                                <span class="n">x_val</span> <span class="o">=</span> <span class="n">val</span>
                                <span class="n">x_temp</span> <span class="o">=</span> <span class="n">t</span>
                                <span class="n">x_doping</span> <span class="o">=</span> <span class="n">doping_lvl</span>
                                <span class="n">x_isotropic</span> <span class="o">=</span> <span class="n">isotropic</span>

            <span class="n">output</span><span class="p">[</span><span class="n">pn</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;value&#39;</span><span class="p">:</span> <span class="n">x_val</span><span class="p">,</span> <span class="s1">&#39;temperature&#39;</span><span class="p">:</span> <span class="n">x_temp</span><span class="p">,</span>
                          <span class="s1">&#39;doping&#39;</span><span class="p">:</span> <span class="n">x_doping</span><span class="p">,</span> <span class="s1">&#39;isotropic&#39;</span><span class="p">:</span> <span class="n">x_isotropic</span><span class="p">}</span>
            <span class="n">x_val</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="n">maximize</span><span class="p">:</span>
            <span class="n">max_type</span> <span class="o">=</span> <span class="s1">&#39;p&#39;</span> <span class="k">if</span> <span class="n">output</span><span class="p">[</span><span class="s1">&#39;p&#39;</span><span class="p">][</span><span class="s1">&#39;value&#39;</span><span class="p">]</span> <span class="o">&gt;=</span> \
                              <span class="n">output</span><span class="p">[</span><span class="s1">&#39;n&#39;</span><span class="p">][</span><span class="s1">&#39;value&#39;</span><span class="p">]</span> <span class="k">else</span> <span class="s1">&#39;n&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">max_type</span> <span class="o">=</span> <span class="s1">&#39;p&#39;</span> <span class="k">if</span> <span class="n">output</span><span class="p">[</span><span class="s1">&#39;p&#39;</span><span class="p">][</span><span class="s1">&#39;value&#39;</span><span class="p">]</span> <span class="o">&lt;=</span> \
                              <span class="n">output</span><span class="p">[</span><span class="s1">&#39;n&#39;</span><span class="p">][</span><span class="s1">&#39;value&#39;</span><span class="p">]</span> <span class="k">else</span> <span class="s1">&#39;n&#39;</span>

        <span class="n">output</span><span class="p">[</span><span class="s1">&#39;best&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">output</span><span class="p">[</span><span class="n">max_type</span><span class="p">]</span>
        <span class="n">output</span><span class="p">[</span><span class="s1">&#39;best&#39;</span><span class="p">][</span><span class="s1">&#39;carrier_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">max_type</span>

        <span class="k">return</span> <span class="n">output</span></div>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">_format_to_output</span><span class="p">(</span><span class="n">tensor</span><span class="p">,</span> <span class="n">tensor_doping</span><span class="p">,</span> <span class="n">output</span><span class="p">,</span> <span class="n">doping_levels</span><span class="p">,</span>
                          <span class="n">multi</span><span class="o">=</span><span class="mf">1.0</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">doping_levels</span><span class="p">:</span>
            <span class="n">full_tensor</span> <span class="o">=</span> <span class="n">tensor_doping</span>
            <span class="n">result</span> <span class="o">=</span> <span class="p">{</span><span class="n">doping</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">tensor_doping</span><span class="p">[</span><span class="n">doping</span><span class="p">]}</span> <span class="k">for</span> <span class="n">doping</span>
                      <span class="ow">in</span> <span class="n">tensor_doping</span><span class="p">}</span>
            <span class="k">for</span> <span class="n">doping</span> <span class="ow">in</span> <span class="n">full_tensor</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">temp</span> <span class="ow">in</span> <span class="n">full_tensor</span><span class="p">[</span><span class="n">doping</span><span class="p">]:</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">full_tensor</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">temp</span><span class="p">])):</span>
                        <span class="k">if</span> <span class="n">output</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;eig&#39;</span><span class="p">,</span> <span class="s1">&#39;eigs&#39;</span><span class="p">]:</span>
                            <span class="n">result</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span>
                                <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">eigh</span><span class="p">(</span><span class="n">full_tensor</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">temp</span><span class="p">][</span><span class="n">i</span><span class="p">])[</span>
                                    <span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">multi</span><span class="p">))</span>
                        <span class="k">elif</span> <span class="n">output</span> <span class="o">==</span> <span class="s1">&#39;tensor&#39;</span><span class="p">:</span>
                            <span class="n">result</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                                <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">full_tensor</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">temp</span><span class="p">][</span><span class="n">i</span><span class="p">])</span> <span class="o">*</span> <span class="n">multi</span><span class="p">)</span>
                        <span class="k">elif</span> <span class="n">output</span> <span class="o">==</span> <span class="s1">&#39;average&#39;</span><span class="p">:</span>
                            <span class="n">result</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                                <span class="p">(</span><span class="n">full_tensor</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">temp</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
                                 <span class="o">+</span> <span class="n">full_tensor</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">temp</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
                                 <span class="o">+</span> <span class="n">full_tensor</span><span class="p">[</span><span class="n">doping</span><span class="p">][</span><span class="n">temp</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="mi">2</span><span class="p">][</span>
                                     <span class="mi">2</span><span class="p">])</span> <span class="o">*</span> <span class="n">multi</span> <span class="o">/</span> <span class="mf">3.0</span><span class="p">)</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Unknown output format: &quot;</span>
                                             <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">output</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">full_tensor</span> <span class="o">=</span> <span class="n">tensor</span>
            <span class="n">result</span> <span class="o">=</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">tensor</span><span class="p">}</span>
            <span class="k">for</span> <span class="n">temp</span> <span class="ow">in</span> <span class="n">full_tensor</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">tensor</span><span class="p">[</span><span class="n">temp</span><span class="p">])):</span>
                    <span class="k">if</span> <span class="n">output</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;eig&#39;</span><span class="p">,</span> <span class="s1">&#39;eigs&#39;</span><span class="p">]:</span>
                        <span class="n">result</span><span class="p">[</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span>
                            <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">eigh</span><span class="p">(</span><span class="n">full_tensor</span><span class="p">[</span><span class="n">temp</span><span class="p">][</span><span class="n">i</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">multi</span><span class="p">))</span>
                    <span class="k">elif</span> <span class="n">output</span> <span class="o">==</span> <span class="s1">&#39;tensor&#39;</span><span class="p">:</span>
                        <span class="n">result</span><span class="p">[</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                            <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">full_tensor</span><span class="p">[</span><span class="n">temp</span><span class="p">][</span><span class="n">i</span><span class="p">])</span> <span class="o">*</span> <span class="n">multi</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">output</span> <span class="o">==</span> <span class="s1">&#39;average&#39;</span><span class="p">:</span>
                        <span class="n">result</span><span class="p">[</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">full_tensor</span><span class="p">[</span><span class="n">temp</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
                                             <span class="o">+</span> <span class="n">full_tensor</span><span class="p">[</span><span class="n">temp</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
                                             <span class="o">+</span> <span class="n">full_tensor</span><span class="p">[</span><span class="n">temp</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="mi">2</span><span class="p">][</span>
                                                 <span class="mi">2</span><span class="p">])</span> <span class="o">*</span> <span class="n">multi</span> <span class="o">/</span> <span class="mf">3.0</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Unknown output format: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span>
                                         <span class="nb">format</span><span class="p">(</span><span class="n">output</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">result</span>

<div class="viewcode-block" id="BoltztrapAnalyzer.get_complete_dos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.get_complete_dos">[docs]</a>    <span class="k">def</span> <span class="nf">get_complete_dos</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">analyzer_for_second_spin</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Gives a CompleteDos object with the DOS from the interpolated</span>
<span class="sd">            projected band structure</span>
<span class="sd">            Args:</span>
<span class="sd">                the structure (necessary to identify sites for projection)</span>
<span class="sd">                analyzer_for_second_spin must be specified to have a</span>
<span class="sd">                CompleteDos with both Spin components</span>
<span class="sd">            Returns:</span>
<span class="sd">                a CompleteDos object</span>
<span class="sd">            Example of use in case of spin polarized case:</span>

<span class="sd">                BoltztrapRunner(bs=bs,nelec=10,run_type=&quot;DOS&quot;,spin=1).run(path_dir=&#39;dos_up/&#39;)</span>
<span class="sd">                an_up=BoltztrapAnalyzer.from_files(&quot;dos_up/boltztrap/&quot;,dos_spin=1)</span>

<span class="sd">                BoltztrapRunner(bs=bs,nelec=10,run_type=&quot;DOS&quot;,spin=-1).run(path_dir=&#39;dos_dw/&#39;)</span>
<span class="sd">                an_dw=BoltztrapAnalyzer.from_files(&quot;dos_dw/boltztrap/&quot;,dos_spin=-1)</span>

<span class="sd">                cdos=an_up.get_complete_dos(bs.structure,an_dw)</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">pdoss</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">spin_1</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dos</span><span class="o">.</span><span class="n">densities</span><span class="o">.</span><span class="n">keys</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span>

        <span class="k">if</span> <span class="n">analyzer_for_second_spin</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="o">.</span><span class="n">all</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dos</span><span class="o">.</span><span class="n">energies</span> <span class="o">==</span>
                          <span class="n">analyzer_for_second_spin</span><span class="o">.</span><span class="n">dos</span><span class="o">.</span><span class="n">energies</span><span class="p">):</span>
                <span class="k">raise</span> <span class="n">BoltztrapError</span><span class="p">(</span>
                    <span class="s2">&quot;Dos merging error: energies of the two dos are different&quot;</span><span class="p">)</span>

            <span class="n">spin_2</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">analyzer_for_second_spin</span><span class="o">.</span><span class="n">dos</span><span class="o">.</span><span class="n">densities</span><span class="o">.</span><span class="n">keys</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">spin_1</span> <span class="o">==</span> <span class="n">spin_2</span><span class="p">:</span>
                <span class="k">raise</span> <span class="n">BoltztrapError</span><span class="p">(</span>
                    <span class="s2">&quot;Dos merging error: spin component are the same&quot;</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_dos_partial</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">structure</span><span class="o">.</span><span class="n">sites</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">)]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">pdoss</span><span class="p">:</span>
                <span class="n">pdoss</span><span class="p">[</span><span class="n">structure</span><span class="o">.</span><span class="n">sites</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">)]]</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">o</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_dos_partial</span><span class="p">[</span><span class="n">s</span><span class="p">]:</span>
                <span class="k">if</span> <span class="n">Orbital</span><span class="p">[</span><span class="n">o</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">pdoss</span><span class="p">[</span><span class="n">structure</span><span class="o">.</span><span class="n">sites</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">)]]:</span>
                    <span class="n">pdoss</span><span class="p">[</span><span class="n">structure</span><span class="o">.</span><span class="n">sites</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">)]][</span><span class="n">Orbital</span><span class="p">[</span><span class="n">o</span><span class="p">]]</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="n">pdoss</span><span class="p">[</span><span class="n">structure</span><span class="o">.</span><span class="n">sites</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">)]][</span><span class="n">Orbital</span><span class="p">[</span><span class="n">o</span><span class="p">]][</span>
                    <span class="n">spin_1</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_dos_partial</span><span class="p">[</span><span class="n">s</span><span class="p">][</span><span class="n">o</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">analyzer_for_second_spin</span><span class="p">:</span>
                    <span class="n">pdoss</span><span class="p">[</span><span class="n">structure</span><span class="o">.</span><span class="n">sites</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">)]][</span><span class="n">Orbital</span><span class="p">[</span><span class="n">o</span><span class="p">]][</span>
                        <span class="n">spin_2</span><span class="p">]</span> <span class="o">=</span> <span class="n">analyzer_for_second_spin</span><span class="o">.</span><span class="n">_dos_partial</span><span class="p">[</span><span class="n">s</span><span class="p">][</span><span class="n">o</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">analyzer_for_second_spin</span><span class="p">:</span>
            <span class="n">tdos</span> <span class="o">=</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dos</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dos</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span>
                       <span class="p">{</span><span class="n">spin_1</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">dos</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span><span class="n">spin_1</span><span class="p">],</span>
                        <span class="n">spin_2</span><span class="p">:</span> <span class="n">analyzer_for_second_spin</span><span class="o">.</span><span class="n">dos</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span>
                            <span class="n">spin_2</span><span class="p">]})</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">tdos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dos</span>

        <span class="k">return</span> <span class="n">CompleteDos</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">total_dos</span><span class="o">=</span><span class="n">tdos</span><span class="p">,</span> <span class="n">pdoss</span><span class="o">=</span><span class="n">pdoss</span><span class="p">)</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.get_mu_bounds"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.get_mu_bounds">[docs]</a>    <span class="k">def</span> <span class="nf">get_mu_bounds</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">temp</span><span class="o">=</span><span class="mi">300</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param temp: Temperature.</span>
<span class="sd">        :return: The chemical potential bounds at that temperature.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">min</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mu_doping</span><span class="p">[</span><span class="s1">&#39;p&#39;</span><span class="p">][</span><span class="n">temp</span><span class="p">]),</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mu_doping</span><span class="p">[</span><span class="s1">&#39;n&#39;</span><span class="p">][</span><span class="n">temp</span><span class="p">])</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.get_carrier_concentration"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.get_carrier_concentration">[docs]</a>    <span class="k">def</span> <span class="nf">get_carrier_concentration</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        gives the carrier concentration (in cm^-3)</span>

<span class="sd">        Returns</span>
<span class="sd">            a dictionary {temp:[]} with an array of carrier concentration</span>
<span class="sd">            (in cm^-3) at each temperature</span>
<span class="sd">            The array relates to each step of electron chemical potential</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="p">{</span><span class="n">temp</span><span class="p">:</span> <span class="p">[</span><span class="mf">1e24</span> <span class="o">*</span> <span class="n">i</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">vol</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_carrier_conc</span><span class="p">[</span><span class="n">temp</span><span class="p">]]</span>
                <span class="k">for</span> <span class="n">temp</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_carrier_conc</span><span class="p">}</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.get_hall_carrier_concentration"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.get_hall_carrier_concentration">[docs]</a>    <span class="k">def</span> <span class="nf">get_hall_carrier_concentration</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        gives the Hall carrier concentration (in cm^-3). This is the trace of</span>
<span class="sd">        the Hall tensor (see Boltztrap source code) Hall carrier concentration</span>
<span class="sd">        are not always exactly the same than carrier concentration.</span>

<span class="sd">        Returns</span>
<span class="sd">            a dictionary {temp:[]} with an array of Hall carrier concentration</span>
<span class="sd">            (in cm^-3) at each temperature The array relates to each step of</span>
<span class="sd">            electron chemical potential</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">result</span> <span class="o">=</span> <span class="p">{</span><span class="n">temp</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">temp</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_hall</span><span class="p">}</span>
        <span class="k">for</span> <span class="n">temp</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_hall</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_hall</span><span class="p">[</span><span class="n">temp</span><span class="p">]:</span>
                <span class="n">trace</span> <span class="o">=</span> <span class="p">(</span><span class="n">i</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">2</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">i</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">i</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">][</span><span class="mi">2</span><span class="p">])</span> <span class="o">/</span> <span class="mf">3.0</span>
                <span class="k">if</span> <span class="n">trace</span> <span class="o">!=</span> <span class="mf">0.0</span><span class="p">:</span>
                    <span class="n">result</span><span class="p">[</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">1e-6</span> <span class="o">/</span> <span class="p">(</span><span class="n">trace</span> <span class="o">*</span> <span class="n">constants</span><span class="o">.</span><span class="n">e</span><span class="p">))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">result</span><span class="p">[</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">result</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.parse_outputtrans"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.parse_outputtrans">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">parse_outputtrans</span><span class="p">(</span><span class="n">path_dir</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parses .outputtrans file</span>

<span class="sd">        Args:</span>
<span class="sd">            path_dir: dir containing boltztrap.outputtrans</span>

<span class="sd">        Returns:</span>
<span class="sd">            tuple - (run_type, warning, efermi, gap, doping_levels)</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">run_type</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">warning</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">efermi</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">gap</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">doping_levels</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap.outputtrans&quot;</span><span class="p">),</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> \
                <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="k">if</span> <span class="s2">&quot;WARNING&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                    <span class="n">warning</span> <span class="o">=</span> <span class="n">line</span>
                <span class="k">elif</span> <span class="s2">&quot;Calc type:&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                    <span class="n">run_type</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
                <span class="k">elif</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;VBM&quot;</span><span class="p">):</span>
                    <span class="n">efermi</span> <span class="o">=</span> <span class="n">Energy</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">],</span> <span class="s2">&quot;Ry&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;eV&quot;</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;Egap:&quot;</span><span class="p">):</span>
                    <span class="n">gap</span> <span class="o">=</span> <span class="n">Energy</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]),</span> <span class="s2">&quot;Ry&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;eV&quot;</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;Doping level number&quot;</span><span class="p">):</span>
                    <span class="n">doping_levels</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">6</span><span class="p">]))</span>

        <span class="k">return</span> <span class="n">run_type</span><span class="p">,</span> <span class="n">warning</span><span class="p">,</span> <span class="n">efermi</span><span class="p">,</span> <span class="n">gap</span><span class="p">,</span> <span class="n">doping_levels</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.parse_transdos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.parse_transdos">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">parse_transdos</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="n">efermi</span><span class="p">,</span> <span class="n">dos_spin</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">trim_dos</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parses .transdos (total DOS) and .transdos_x_y (partial DOS) files</span>
<span class="sd">        Args:</span>
<span class="sd">            path_dir: (str) dir containing DOS files</span>
<span class="sd">            efermi: (float) Fermi energy</span>
<span class="sd">            dos_spin: (int) -1 for spin down, +1 for spin up</span>
<span class="sd">            trim_dos: (bool) whether to post-process / trim DOS</span>

<span class="sd">        Returns:</span>
<span class="sd">            tuple - (DOS, dict of partial DOS)</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">data_dos</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;total&#39;</span><span class="p">:</span> <span class="p">[],</span> <span class="s1">&#39;partial&#39;</span><span class="p">:</span> <span class="p">{}}</span>
        <span class="c1"># parse the total DOS data</span>
        <span class="c1"># format is energy, DOS, integrated DOS</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap.transdos&quot;</span><span class="p">),</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">count_series</span> <span class="o">=</span> <span class="mi">0</span>  <span class="c1"># TODO: why is count_series needed?</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">line</span><span class="o">.</span><span class="n">lstrip</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;#&quot;</span><span class="p">):</span>
                    <span class="n">count_series</span> <span class="o">+=</span> <span class="mi">1</span>
                    <span class="k">if</span> <span class="n">count_series</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                        <span class="k">break</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">data_dos</span><span class="p">[</span><span class="s1">&#39;total&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                        <span class="p">[</span><span class="n">Energy</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]),</span> <span class="s2">&quot;Ry&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;eV&quot;</span><span class="p">),</span>
                         <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">])])</span>

        <span class="n">lw_l</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">hg_l</span> <span class="o">=</span> <span class="o">-</span><span class="nb">len</span><span class="p">(</span><span class="n">data_dos</span><span class="p">[</span><span class="s1">&#39;total&#39;</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">trim_dos</span><span class="p">:</span>
            <span class="c1"># Francesco knows what this does</span>
            <span class="c1"># It has something to do with a trick of adding fake energies</span>
            <span class="c1"># at the endpoints of the DOS, and then re-trimming it. This is</span>
            <span class="c1"># to get the same energy scale for up and down spin DOS.</span>
            <span class="n">tmp_data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">data_dos</span><span class="p">[</span><span class="s1">&#39;total&#39;</span><span class="p">])</span>
            <span class="n">tmp_den</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">trim_zeros</span><span class="p">(</span><span class="n">tmp_data</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">],</span> <span class="s1">&#39;f&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]</span>
            <span class="n">lw_l</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp_data</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">])</span> <span class="o">-</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp_den</span><span class="p">)</span>
            <span class="n">tmp_ene</span> <span class="o">=</span> <span class="n">tmp_data</span><span class="p">[</span><span class="n">lw_l</span><span class="p">:,</span> <span class="mi">0</span><span class="p">]</span>
            <span class="n">tmp_den</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">trim_zeros</span><span class="p">(</span><span class="n">tmp_den</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">)[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">hg_l</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp_ene</span><span class="p">)</span> <span class="o">-</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp_den</span><span class="p">)</span>
            <span class="n">tmp_ene</span> <span class="o">=</span> <span class="n">tmp_ene</span><span class="p">[:</span><span class="o">-</span><span class="n">hg_l</span><span class="p">]</span>
            <span class="n">tmp_data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">((</span><span class="n">tmp_ene</span><span class="p">,</span> <span class="n">tmp_den</span><span class="p">))</span><span class="o">.</span><span class="n">T</span>
            <span class="n">data_dos</span><span class="p">[</span><span class="s1">&#39;total&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">tmp_data</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>

        <span class="c1"># parse partial DOS data</span>
        <span class="k">for</span> <span class="n">file_name</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">path_dir</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">file_name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span>
                    <span class="s2">&quot;transdos&quot;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">file_name</span> <span class="o">!=</span> <span class="s1">&#39;boltztrap.transdos&#39;</span><span class="p">:</span>
                <span class="n">tokens</span> <span class="o">=</span> <span class="n">file_name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;.&quot;</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;_&quot;</span><span class="p">)</span>
                <span class="n">site</span> <span class="o">=</span> <span class="n">tokens</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
                <span class="n">orb</span> <span class="o">=</span> <span class="s1">&#39;_&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">tokens</span><span class="p">[</span><span class="mi">2</span><span class="p">:])</span>
                <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="n">file_name</span><span class="p">),</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                        <span class="k">if</span> <span class="ow">not</span> <span class="n">line</span><span class="o">.</span><span class="n">lstrip</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot; #&quot;</span><span class="p">):</span>
                            <span class="k">if</span> <span class="n">site</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">data_dos</span><span class="p">[</span><span class="s1">&#39;partial&#39;</span><span class="p">]:</span>
                                <span class="n">data_dos</span><span class="p">[</span><span class="s1">&#39;partial&#39;</span><span class="p">][</span><span class="n">site</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                            <span class="k">if</span> <span class="n">orb</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">data_dos</span><span class="p">[</span><span class="s1">&#39;partial&#39;</span><span class="p">][</span><span class="n">site</span><span class="p">]:</span>
                                <span class="n">data_dos</span><span class="p">[</span><span class="s1">&#39;partial&#39;</span><span class="p">][</span><span class="n">site</span><span class="p">][</span><span class="n">orb</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
                            <span class="n">data_dos</span><span class="p">[</span><span class="s1">&#39;partial&#39;</span><span class="p">][</span><span class="n">site</span><span class="p">][</span><span class="n">orb</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                                <span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]))</span>
                <span class="n">data_dos</span><span class="p">[</span><span class="s1">&#39;partial&#39;</span><span class="p">][</span><span class="n">site</span><span class="p">][</span><span class="n">orb</span><span class="p">]</span> <span class="o">=</span> <span class="n">data_dos</span><span class="p">[</span><span class="s1">&#39;partial&#39;</span><span class="p">][</span><span class="n">site</span><span class="p">][</span>
                                                     <span class="n">orb</span><span class="p">][</span><span class="n">lw_l</span><span class="p">:</span><span class="o">-</span><span class="n">hg_l</span><span class="p">]</span>

        <span class="n">dos_full</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;energy&#39;</span><span class="p">:</span> <span class="p">[],</span> <span class="s1">&#39;density&#39;</span><span class="p">:</span> <span class="p">[]}</span>

        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">data_dos</span><span class="p">[</span><span class="s1">&#39;total&#39;</span><span class="p">]:</span>
            <span class="n">dos_full</span><span class="p">[</span><span class="s1">&#39;energy&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">dos_full</span><span class="p">[</span><span class="s1">&#39;density&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>

        <span class="n">dos</span> <span class="o">=</span> <span class="n">Dos</span><span class="p">(</span><span class="n">efermi</span><span class="p">,</span> <span class="n">dos_full</span><span class="p">[</span><span class="s1">&#39;energy&#39;</span><span class="p">],</span>
                  <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="n">dos_spin</span><span class="p">):</span> <span class="n">dos_full</span><span class="p">[</span><span class="s1">&#39;density&#39;</span><span class="p">]})</span>
        <span class="n">dos_partial</span> <span class="o">=</span> <span class="n">data_dos</span><span class="p">[</span><span class="s1">&#39;partial&#39;</span><span class="p">]</span>  <span class="c1"># TODO: make this real DOS object?</span>

        <span class="k">return</span> <span class="n">dos</span><span class="p">,</span> <span class="n">dos_partial</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.parse_intrans"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.parse_intrans">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">parse_intrans</span><span class="p">(</span><span class="n">path_dir</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parses boltztrap.intrans mainly to extract the value of scissor applied</span>
<span class="sd">        to the bands or some other inputs</span>

<span class="sd">        Args:</span>
<span class="sd">            path_dir: (str) dir containing the boltztrap.intrans file</span>

<span class="sd">        Returns:</span>
<span class="sd">            intrans (dict): a dictionary containing various inputs that had</span>
<span class="sd">                been used in the Boltztrap run.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">intrans</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap.intrans&quot;</span><span class="p">),</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="k">if</span> <span class="s2">&quot;iskip&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                    <span class="n">intrans</span><span class="p">[</span><span class="s2">&quot;scissor&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Energy</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">)[</span><span class="mi">3</span><span class="p">]),</span>
                                                <span class="s2">&quot;Ry&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;eV&quot;</span><span class="p">)</span>
                <span class="k">if</span> <span class="s2">&quot;HISTO&quot;</span> <span class="ow">in</span> <span class="n">line</span> <span class="ow">or</span> <span class="s2">&quot;TETRA&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                    <span class="n">intrans</span><span class="p">[</span><span class="s2">&quot;dos_type&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">line</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">intrans</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.parse_struct"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.parse_struct">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">parse_struct</span><span class="p">(</span><span class="n">path_dir</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parses boltztrap.struct file (only the volume)</span>
<span class="sd">        Args:</span>
<span class="sd">            path_dir: (str) dir containing the boltztrap.struct file</span>

<span class="sd">        Returns:</span>
<span class="sd">            (float) volume</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap.struct&quot;</span><span class="p">),</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">tokens</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readlines</span><span class="p">()</span>
            <span class="k">return</span> <span class="n">Lattice</span><span class="p">([[</span><span class="n">Length</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">tokens</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="n">j</span><span class="p">]),</span> <span class="s2">&quot;bohr&quot;</span><span class="p">)</span><span class="o">.</span>
                           <span class="n">to</span><span class="p">(</span><span class="s2">&quot;ang&quot;</span><span class="p">)</span> <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span>
                            <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">)])</span><span class="o">.</span><span class="n">volume</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.parse_cond_and_hall"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.parse_cond_and_hall">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">parse_cond_and_hall</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="n">doping_levels</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parses the conductivity and Hall tensors</span>
<span class="sd">        Args:</span>
<span class="sd">            path_dir: Path containing .condtens / .halltens files</span>
<span class="sd">            doping_levels: ([float]) - doping lvls, parse outtrans to get this</span>

<span class="sd">        Returns:</span>
<span class="sd">            mu_steps, cond, seebeck, kappa, hall, pn_doping_levels,</span>
<span class="sd">            mu_doping, seebeck_doping, cond_doping, kappa_doping,</span>
<span class="sd">            hall_doping, carrier_conc</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># Step 1: parse raw data but do not convert to final format</span>
        <span class="n">t_steps</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
        <span class="n">mu_steps</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
        <span class="n">data_full</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">data_hall</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">data_doping_full</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">data_doping_hall</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">doping_levels</span> <span class="o">=</span> <span class="n">doping_levels</span> <span class="ow">or</span> <span class="p">[]</span>

        <span class="c1"># parse the full conductivity/Seebeck/kappa0/etc data</span>
        <span class="c1"># also initialize t_steps and mu_steps</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap.condtens&quot;</span><span class="p">),</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;#&quot;</span><span class="p">):</span>
                    <span class="n">mu_steps</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]))</span>
                    <span class="n">t_steps</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">])))</span>
                    <span class="n">data_full</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()])</span>

        <span class="c1"># parse the full Hall tensor</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap.halltens&quot;</span><span class="p">),</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;#&quot;</span><span class="p">):</span>
                    <span class="n">data_hall</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()])</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">doping_levels</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="c1"># parse doping levels version of full cond. tensor, etc.</span>
            <span class="k">with</span> <span class="nb">open</span><span class="p">(</span>
                    <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap.condtens_fixdoping&quot;</span><span class="p">),</span>
                    <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;#&quot;</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">2</span><span class="p">:</span>
                        <span class="n">data_doping_full</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
                                                 <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()])</span>

            <span class="c1"># parse doping levels version of full hall tensor</span>
            <span class="k">with</span> <span class="nb">open</span><span class="p">(</span>
                    <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap.halltens_fixdoping&quot;</span><span class="p">),</span>
                    <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;#&quot;</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">2</span><span class="p">:</span>
                        <span class="n">data_doping_hall</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                            <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()])</span>

        <span class="c1"># Step 2: convert raw data to final format</span>

        <span class="c1"># sort t and mu_steps (b/c they are sets not lists)</span>
        <span class="c1"># and convert to correct energy</span>
        <span class="n">t_steps</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">([</span><span class="n">t</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">])</span>
        <span class="n">mu_steps</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">([</span><span class="n">Energy</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="s2">&quot;Ry&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;eV&quot;</span><span class="p">)</span> <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">mu_steps</span><span class="p">])</span>

        <span class="c1"># initialize output variables - could use defaultdict instead</span>
        <span class="c1"># I am leaving things like this for clarity</span>
        <span class="n">cond</span> <span class="o">=</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">}</span>
        <span class="n">seebeck</span> <span class="o">=</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">}</span>
        <span class="n">kappa</span> <span class="o">=</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">}</span>
        <span class="n">hall</span> <span class="o">=</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">}</span>
        <span class="n">carrier_conc</span> <span class="o">=</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">}</span>

        <span class="n">mu_doping</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;p&#39;</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">},</span>
                     <span class="s1">&#39;n&#39;</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">}}</span>
        <span class="n">seebeck_doping</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;p&#39;</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">},</span>
                          <span class="s1">&#39;n&#39;</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">}}</span>
        <span class="n">cond_doping</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;p&#39;</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">},</span>
                       <span class="s1">&#39;n&#39;</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">}}</span>
        <span class="n">kappa_doping</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;p&#39;</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">},</span>
                        <span class="s1">&#39;n&#39;</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">}}</span>
        <span class="n">hall_doping</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;p&#39;</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">},</span>
                       <span class="s1">&#39;n&#39;</span><span class="p">:</span> <span class="p">{</span><span class="n">t</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">t_steps</span><span class="p">}}</span>

        <span class="c1"># process doping levels</span>
        <span class="n">pn_doping_levels</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;p&#39;</span><span class="p">:</span> <span class="p">[],</span> <span class="s1">&#39;n&#39;</span><span class="p">:</span> <span class="p">[]}</span>
        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">doping_levels</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">d</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">pn_doping_levels</span><span class="p">[</span><span class="s1">&#39;p&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">pn_doping_levels</span><span class="p">[</span><span class="s1">&#39;n&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="o">-</span><span class="n">d</span><span class="p">)</span>

        <span class="c1"># process raw conductivity data, etc.</span>
        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data_full</span><span class="p">:</span>
            <span class="n">temp</span><span class="p">,</span> <span class="n">doping</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
            <span class="n">carrier_conc</span><span class="p">[</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">doping</span><span class="p">)</span>

            <span class="n">cond</span><span class="p">[</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">12</span><span class="p">],</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">tolist</span><span class="p">())</span>
            <span class="n">seebeck</span><span class="p">[</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="mi">12</span><span class="p">:</span><span class="mi">21</span><span class="p">],</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">tolist</span><span class="p">())</span>
            <span class="n">kappa</span><span class="p">[</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="mi">21</span><span class="p">:</span><span class="mi">30</span><span class="p">],</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">tolist</span><span class="p">())</span>

        <span class="c1"># process raw Hall data</span>
        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data_hall</span><span class="p">:</span>
            <span class="n">temp</span><span class="p">,</span> <span class="n">doping</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
            <span class="n">hall_tens</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">12</span><span class="p">],</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">tolist</span><span class="p">(),</span>
                         <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="mi">12</span><span class="p">:</span><span class="mi">21</span><span class="p">],</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">tolist</span><span class="p">(),</span>
                         <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="mi">21</span><span class="p">:</span><span class="mi">30</span><span class="p">],</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">tolist</span><span class="p">()]</span>
            <span class="n">hall</span><span class="p">[</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">hall_tens</span><span class="p">)</span>

        <span class="c1"># process doping conductivity data, etc.</span>
        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data_doping_full</span><span class="p">:</span>
            <span class="n">temp</span><span class="p">,</span> <span class="n">doping</span><span class="p">,</span> <span class="n">mu</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">pn</span> <span class="o">=</span> <span class="s1">&#39;p&#39;</span> <span class="k">if</span> <span class="n">doping</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="s1">&#39;n&#39;</span>
            <span class="n">mu_doping</span><span class="p">[</span><span class="n">pn</span><span class="p">][</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Energy</span><span class="p">(</span><span class="n">mu</span><span class="p">,</span> <span class="s2">&quot;Ry&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;eV&quot;</span><span class="p">))</span>
            <span class="n">cond_doping</span><span class="p">[</span><span class="n">pn</span><span class="p">][</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">11</span><span class="p">],</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">tolist</span><span class="p">())</span>
            <span class="n">seebeck_doping</span><span class="p">[</span><span class="n">pn</span><span class="p">][</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="mi">11</span><span class="p">:</span><span class="mi">20</span><span class="p">],</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">tolist</span><span class="p">())</span>
            <span class="n">kappa_doping</span><span class="p">[</span><span class="n">pn</span><span class="p">][</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="mi">20</span><span class="p">:</span><span class="mi">29</span><span class="p">],</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">tolist</span><span class="p">())</span>

        <span class="c1"># process doping Hall data</span>
        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data_doping_hall</span><span class="p">:</span>
            <span class="n">temp</span><span class="p">,</span> <span class="n">doping</span><span class="p">,</span> <span class="n">mu</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">pn</span> <span class="o">=</span> <span class="s1">&#39;p&#39;</span> <span class="k">if</span> <span class="n">doping</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="s1">&#39;n&#39;</span>
            <span class="n">hall_tens</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">11</span><span class="p">],</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">tolist</span><span class="p">(),</span>
                         <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="mi">11</span><span class="p">:</span><span class="mi">20</span><span class="p">],</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">tolist</span><span class="p">(),</span>
                         <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="mi">20</span><span class="p">:</span><span class="mi">29</span><span class="p">],</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">tolist</span><span class="p">()]</span>
            <span class="n">hall_doping</span><span class="p">[</span><span class="n">pn</span><span class="p">][</span><span class="n">temp</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">hall_tens</span><span class="p">)</span>

        <span class="k">return</span> <span class="p">(</span><span class="n">mu_steps</span><span class="p">,</span> <span class="n">cond</span><span class="p">,</span> <span class="n">seebeck</span><span class="p">,</span> <span class="n">kappa</span><span class="p">,</span> <span class="n">hall</span><span class="p">,</span> <span class="n">pn_doping_levels</span><span class="p">,</span>
                <span class="n">mu_doping</span><span class="p">,</span> <span class="n">seebeck_doping</span><span class="p">,</span> <span class="n">cond_doping</span><span class="p">,</span> <span class="n">kappa_doping</span><span class="p">,</span>
                <span class="n">hall_doping</span><span class="p">,</span> <span class="n">carrier_conc</span><span class="p">)</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.from_files"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.from_files">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_files</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="n">dos_spin</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        get a BoltztrapAnalyzer object from a set of files</span>

<span class="sd">        Args:</span>
<span class="sd">            path_dir: directory where the boltztrap files are</span>
<span class="sd">            dos_spin: in DOS mode, set to 1 for spin up and -1 for spin down</span>

<span class="sd">        Returns:</span>
<span class="sd">            a BoltztrapAnalyzer object</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">run_type</span><span class="p">,</span> <span class="n">warning</span><span class="p">,</span> <span class="n">efermi</span><span class="p">,</span> <span class="n">gap</span><span class="p">,</span> <span class="n">doping_levels</span> <span class="o">=</span> \
            <span class="n">BoltztrapAnalyzer</span><span class="o">.</span><span class="n">parse_outputtrans</span><span class="p">(</span><span class="n">path_dir</span><span class="p">)</span>

        <span class="n">vol</span> <span class="o">=</span> <span class="n">BoltztrapAnalyzer</span><span class="o">.</span><span class="n">parse_struct</span><span class="p">(</span><span class="n">path_dir</span><span class="p">)</span>

        <span class="n">intrans</span> <span class="o">=</span> <span class="n">BoltztrapAnalyzer</span><span class="o">.</span><span class="n">parse_intrans</span><span class="p">(</span><span class="n">path_dir</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">run_type</span> <span class="o">==</span> <span class="s2">&quot;BOLTZ&quot;</span><span class="p">:</span>
            <span class="n">dos</span><span class="p">,</span> <span class="n">pdos</span> <span class="o">=</span> <span class="n">BoltztrapAnalyzer</span><span class="o">.</span><span class="n">parse_transdos</span><span class="p">(</span>
                <span class="n">path_dir</span><span class="p">,</span> <span class="n">efermi</span><span class="p">,</span> <span class="n">dos_spin</span><span class="o">=</span><span class="n">dos_spin</span><span class="p">,</span> <span class="n">trim_dos</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

            <span class="p">(</span><span class="n">mu_steps</span><span class="p">,</span> <span class="n">cond</span><span class="p">,</span> <span class="n">seebeck</span><span class="p">,</span> <span class="n">kappa</span><span class="p">,</span> <span class="n">hall</span><span class="p">,</span> <span class="n">pn_doping_levels</span><span class="p">,</span> <span class="n">mu_doping</span><span class="p">,</span>
             <span class="n">seebeck_doping</span><span class="p">,</span> <span class="n">cond_doping</span><span class="p">,</span> <span class="n">kappa_doping</span><span class="p">,</span> <span class="n">hall_doping</span><span class="p">,</span>
             <span class="n">carrier_conc</span><span class="p">)</span> <span class="o">=</span> <span class="n">BoltztrapAnalyzer</span><span class="o">.</span><span class="n">parse_cond_and_hall</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="n">doping_levels</span><span class="p">)</span>

            <span class="k">return</span> <span class="n">BoltztrapAnalyzer</span><span class="p">(</span>
                <span class="n">gap</span><span class="p">,</span> <span class="n">mu_steps</span><span class="p">,</span> <span class="n">cond</span><span class="p">,</span> <span class="n">seebeck</span><span class="p">,</span> <span class="n">kappa</span><span class="p">,</span> <span class="n">hall</span><span class="p">,</span> <span class="n">pn_doping_levels</span><span class="p">,</span>
                <span class="n">mu_doping</span><span class="p">,</span> <span class="n">seebeck_doping</span><span class="p">,</span> <span class="n">cond_doping</span><span class="p">,</span> <span class="n">kappa_doping</span><span class="p">,</span>
                <span class="n">hall_doping</span><span class="p">,</span> <span class="n">intrans</span><span class="p">,</span> <span class="n">dos</span><span class="p">,</span> <span class="n">pdos</span><span class="p">,</span> <span class="n">carrier_conc</span><span class="p">,</span> <span class="n">vol</span><span class="p">,</span> <span class="n">warning</span><span class="p">)</span>

        <span class="k">elif</span> <span class="n">run_type</span> <span class="o">==</span> <span class="s2">&quot;DOS&quot;</span><span class="p">:</span>
            <span class="n">trim</span> <span class="o">=</span> <span class="kc">True</span> <span class="k">if</span> <span class="n">intrans</span><span class="p">[</span><span class="s2">&quot;dos_type&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;HISTO&quot;</span> <span class="k">else</span> <span class="kc">False</span>
            <span class="n">dos</span><span class="p">,</span> <span class="n">pdos</span> <span class="o">=</span> <span class="n">BoltztrapAnalyzer</span><span class="o">.</span><span class="n">parse_transdos</span><span class="p">(</span>
                <span class="n">path_dir</span><span class="p">,</span> <span class="n">efermi</span><span class="p">,</span> <span class="n">dos_spin</span><span class="o">=</span><span class="n">dos_spin</span><span class="p">,</span> <span class="n">trim_dos</span><span class="o">=</span><span class="n">trim</span><span class="p">)</span>

            <span class="k">return</span> <span class="n">BoltztrapAnalyzer</span><span class="p">(</span><span class="n">gap</span><span class="o">=</span><span class="n">gap</span><span class="p">,</span> <span class="n">dos</span><span class="o">=</span><span class="n">dos</span><span class="p">,</span> <span class="n">dos_partial</span><span class="o">=</span><span class="n">pdos</span><span class="p">,</span>
                                     <span class="n">warning</span><span class="o">=</span><span class="n">warning</span><span class="p">,</span> <span class="n">vol</span><span class="o">=</span><span class="n">vol</span><span class="p">)</span>

        <span class="k">elif</span> <span class="n">run_type</span> <span class="o">==</span> <span class="s2">&quot;BANDS&quot;</span><span class="p">:</span>
            <span class="n">bz_kpoints</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">loadtxt</span><span class="p">(</span>
                <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap_band.dat&quot;</span><span class="p">))[:,</span> <span class="o">-</span><span class="mi">3</span><span class="p">:]</span>
            <span class="n">bz_bands</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">loadtxt</span><span class="p">(</span>
                <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s2">&quot;boltztrap_band.dat&quot;</span><span class="p">))[:,</span> <span class="mi">1</span><span class="p">:</span><span class="o">-</span><span class="mi">6</span><span class="p">]</span>
            <span class="k">return</span> <span class="n">BoltztrapAnalyzer</span><span class="p">(</span><span class="n">bz_bands</span><span class="o">=</span><span class="n">bz_bands</span><span class="p">,</span> <span class="n">bz_kpoints</span><span class="o">=</span><span class="n">bz_kpoints</span><span class="p">,</span>
                                     <span class="n">warning</span><span class="o">=</span><span class="n">warning</span><span class="p">,</span> <span class="n">vol</span><span class="o">=</span><span class="n">vol</span><span class="p">)</span>

        <span class="k">elif</span> <span class="n">run_type</span> <span class="o">==</span> <span class="s2">&quot;FERMI&quot;</span><span class="p">:</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            &quot;&quot;&quot;</span>

            <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s1">&#39;boltztrap_BZ.cube&#39;</span><span class="p">)):</span>
                <span class="n">fs_data</span> <span class="o">=</span> <span class="n">read_cube_file</span><span class="p">(</span>
                    <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s1">&#39;boltztrap_BZ.cube&#39;</span><span class="p">))</span>
            <span class="k">elif</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s1">&#39;fort.30&#39;</span><span class="p">)):</span>
                <span class="n">fs_data</span> <span class="o">=</span> <span class="n">read_cube_file</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_dir</span><span class="p">,</span> <span class="s1">&#39;fort.30&#39;</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="n">BoltztrapError</span><span class="p">(</span><span class="s2">&quot;No data file found for fermi surface&quot;</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">BoltztrapAnalyzer</span><span class="p">(</span><span class="n">fermi_surface_data</span><span class="o">=</span><span class="n">fs_data</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Run type: </span><span class="si">{}</span><span class="s2"> not recognized!&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">run_type</span><span class="p">))</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.as_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: MSONable dict.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">results</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;gap&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">gap</span><span class="p">,</span>
                   <span class="s1">&#39;mu_steps&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">mu_steps</span><span class="p">,</span>
                   <span class="s1">&#39;intrans&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">intrans</span><span class="p">,</span>
                   <span class="s1">&#39;cond&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cond</span><span class="p">,</span>
                   <span class="s1">&#39;seebeck&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck</span><span class="p">,</span>
                   <span class="s1">&#39;kappa&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_kappa</span><span class="p">,</span>
                   <span class="s1">&#39;hall&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_hall</span><span class="p">,</span>
                   <span class="s1">&#39;doping&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">doping</span><span class="p">,</span>
                   <span class="s1">&#39;mu_doping&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">mu_doping</span><span class="p">,</span>
                   <span class="s1">&#39;seebeck_doping&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_seebeck_doping</span><span class="p">,</span>
                   <span class="s1">&#39;cond_doping&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cond_doping</span><span class="p">,</span>
                   <span class="s1">&#39;kappa_doping&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_kappa_doping</span><span class="p">,</span>
                   <span class="s1">&#39;hall_doping&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_hall_doping</span><span class="p">,</span>
                   <span class="s1">&#39;dos&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">dos</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
                   <span class="s1">&#39;dos_partial&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_dos_partial</span><span class="p">,</span>
                   <span class="s1">&#39;carrier_conc&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_carrier_conc</span><span class="p">,</span>
                   <span class="s1">&#39;vol&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">vol</span><span class="p">,</span>
                   <span class="s1">&#39;warning&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">warning</span><span class="p">}</span>
        <span class="k">return</span> <span class="n">jsanitize</span><span class="p">(</span><span class="n">results</span><span class="p">)</span></div>

<div class="viewcode-block" id="BoltztrapAnalyzer.from_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.BoltztrapAnalyzer.from_dict">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="n">data</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param data: Dict representation.</span>
<span class="sd">        :return: BoltztrapAnalyzer</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">def</span> <span class="nf">_make_float_array</span><span class="p">(</span><span class="n">a</span><span class="p">):</span>
            <span class="n">res</span> <span class="o">=</span> <span class="p">[[</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">]]</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
                    <span class="n">res</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">])</span>
            <span class="k">return</span> <span class="n">res</span>

        <span class="k">def</span> <span class="nf">_make_float_hall</span><span class="p">(</span><span class="n">a</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">a</span><span class="p">[:</span><span class="mi">27</span><span class="p">]]</span>

        <span class="n">gap</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;gap&#39;</span><span class="p">)</span>
        <span class="n">mu_steps</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;mu_steps&#39;</span><span class="p">]]</span> <span class="k">if</span> \
            <span class="s1">&#39;mu_steps&#39;</span> <span class="ow">in</span> <span class="n">data</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="n">cond</span> <span class="o">=</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="p">[</span><span class="n">_make_float_array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;cond&#39;</span><span class="p">][</span><span class="n">d</span><span class="p">]]</span>
                <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;cond&#39;</span><span class="p">]}</span> <span class="k">if</span> <span class="s1">&#39;cond&#39;</span> <span class="ow">in</span> <span class="n">data</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="n">seebeck</span> <span class="o">=</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="p">[</span><span class="n">_make_float_array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;seebeck&#39;</span><span class="p">][</span><span class="n">d</span><span class="p">]]</span>
                   <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;seebeck&#39;</span><span class="p">]}</span> <span class="k">if</span> <span class="s1">&#39;seebeck&#39;</span> <span class="ow">in</span> <span class="n">data</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="n">kappa</span> <span class="o">=</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="p">[</span><span class="n">_make_float_array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;kappa&#39;</span><span class="p">][</span><span class="n">d</span><span class="p">]]</span>
                 <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;kappa&#39;</span><span class="p">]}</span> <span class="k">if</span> <span class="s1">&#39;kappa&#39;</span> <span class="ow">in</span> <span class="n">data</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="n">hall</span> <span class="o">=</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="p">[</span><span class="n">_make_float_hall</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;hall&#39;</span><span class="p">][</span><span class="n">d</span><span class="p">]]</span>
                <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;hall&#39;</span><span class="p">]}</span> <span class="k">if</span> <span class="s1">&#39;hall&#39;</span> <span class="ow">in</span> <span class="n">data</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="n">doping</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;p&#39;</span><span class="p">:</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;doping&#39;</span><span class="p">][</span><span class="s1">&#39;p&#39;</span><span class="p">]],</span>
                  <span class="s1">&#39;n&#39;</span><span class="p">:</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;doping&#39;</span><span class="p">][</span><span class="s1">&#39;n&#39;</span><span class="p">]]}</span> <span class="k">if</span> \
            <span class="s1">&#39;doping&#39;</span> <span class="ow">in</span> <span class="n">data</span> <span class="k">else</span> <span class="kc">None</span>

        <span class="n">mu_doping</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;p&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="p">[</span>
            <span class="nb">float</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;mu_doping&#39;</span><span class="p">][</span><span class="s1">&#39;p&#39;</span><span class="p">][</span><span class="n">d</span><span class="p">]]</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span>
            <span class="n">data</span><span class="p">[</span><span class="s1">&#39;mu_doping&#39;</span><span class="p">][</span><span class="s1">&#39;p&#39;</span><span class="p">]},</span> <span class="s1">&#39;n&#39;</span><span class="p">:</span>
            <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;mu_doping&#39;</span><span class="p">][</span><span class="s1">&#39;n&#39;</span><span class="p">][</span><span class="n">d</span><span class="p">]]</span>
             <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;mu_doping&#39;</span><span class="p">][</span>
                 <span class="s1">&#39;n&#39;</span><span class="p">]}}</span> <span class="k">if</span> <span class="s1">&#39;mu_doping&#39;</span> <span class="ow">in</span> <span class="n">data</span> <span class="k">else</span> <span class="kc">None</span>

        <span class="n">seebeck_doping</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;p&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="p">[</span>
            <span class="n">_make_float_array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;seebeck_doping&#39;</span><span class="p">][</span><span class="s1">&#39;p&#39;</span><span class="p">][</span><span class="n">d</span><span class="p">]]</span>
            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;seebeck_doping&#39;</span><span class="p">][</span><span class="s1">&#39;p&#39;</span><span class="p">]},</span> <span class="s1">&#39;n&#39;</span><span class="p">:</span>
            <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="p">[</span><span class="n">_make_float_array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span>
                      <span class="n">data</span><span class="p">[</span><span class="s1">&#39;seebeck_doping&#39;</span><span class="p">][</span><span class="s1">&#39;n&#39;</span><span class="p">][</span><span class="n">d</span><span class="p">]]</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span>
             <span class="n">data</span><span class="p">[</span><span class="s1">&#39;seebeck_doping&#39;</span><span class="p">][</span>
                 <span class="s1">&#39;n&#39;</span><span class="p">]}}</span> <span class="k">if</span> <span class="s1">&#39;seebeck_doping&#39;</span> <span class="ow">in</span> <span class="n">data</span> \
            <span class="k">else</span> <span class="kc">None</span>

        <span class="n">cond_doping</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;p&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="p">[</span><span class="n">_make_float_array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;cond_doping&#39;</span><span class="p">][</span><span class="s1">&#39;p&#39;</span><span class="p">][</span><span class="n">d</span><span class="p">]]</span>
                             <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;cond_doping&#39;</span><span class="p">][</span><span class="s1">&#39;p&#39;</span><span class="p">]},</span>
                       <span class="s1">&#39;n&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="p">[</span><span class="n">_make_float_array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;cond_doping&#39;</span><span class="p">][</span><span class="s1">&#39;n&#39;</span><span class="p">][</span><span class="n">d</span><span class="p">]]</span>
                             <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;cond_doping&#39;</span><span class="p">][</span><span class="s1">&#39;n&#39;</span><span class="p">]}}</span> <span class="k">if</span> <span class="s1">&#39;cond_doping&#39;</span> <span class="ow">in</span> <span class="n">data</span> <span class="k">else</span> <span class="kc">None</span>

        <span class="n">kappa_doping</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;p&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="p">[</span><span class="n">_make_float_array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;kappa_doping&#39;</span><span class="p">][</span><span class="s1">&#39;p&#39;</span><span class="p">][</span><span class="n">d</span><span class="p">]]</span>
                              <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;kappa_doping&#39;</span><span class="p">][</span><span class="s1">&#39;p&#39;</span><span class="p">]},</span>
                        <span class="s1">&#39;n&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="p">[</span><span class="n">_make_float_array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;kappa_doping&#39;</span><span class="p">][</span><span class="s1">&#39;n&#39;</span><span class="p">][</span><span class="n">d</span><span class="p">]]</span>
                              <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;kappa_doping&#39;</span><span class="p">][</span><span class="s1">&#39;n&#39;</span><span class="p">]}}</span> <span class="k">if</span> <span class="s1">&#39;kappa_doping&#39;</span> <span class="ow">in</span> <span class="n">data</span> <span class="k">else</span> <span class="kc">None</span>

        <span class="n">hall_doping</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;p&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="p">[</span><span class="n">_make_float_hall</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;hall_doping&#39;</span><span class="p">][</span><span class="s1">&#39;p&#39;</span><span class="p">][</span><span class="n">d</span><span class="p">]]</span>
                             <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;hall_doping&#39;</span><span class="p">][</span><span class="s1">&#39;p&#39;</span><span class="p">]},</span>
                       <span class="s1">&#39;n&#39;</span><span class="p">:</span> <span class="p">{</span><span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="p">[</span><span class="n">_make_float_hall</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;hall_doping&#39;</span><span class="p">][</span><span class="s1">&#39;n&#39;</span><span class="p">][</span><span class="n">d</span><span class="p">]]</span>
                             <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;hall_doping&#39;</span><span class="p">][</span><span class="s1">&#39;n&#39;</span><span class="p">]}}</span> <span class="k">if</span> <span class="s2">&quot;hall_doping&quot;</span> <span class="ow">in</span> <span class="n">data</span> <span class="k">else</span> <span class="kc">None</span>

        <span class="n">dos</span> <span class="o">=</span> <span class="n">Dos</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;dos&#39;</span><span class="p">])</span> <span class="k">if</span> <span class="s1">&#39;dos&#39;</span> <span class="ow">in</span> <span class="n">data</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="n">dos_partial</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;dos_partial&#39;</span><span class="p">)</span>
        <span class="n">carrier_conc</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;carrier_conc&#39;</span><span class="p">)</span>
        <span class="n">vol</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;vol&#39;</span><span class="p">)</span>
        <span class="n">warning</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;warning&#39;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">BoltztrapAnalyzer</span><span class="p">(</span><span class="n">gap</span><span class="o">=</span><span class="n">gap</span><span class="p">,</span>
                                 <span class="n">mu_steps</span><span class="o">=</span><span class="n">mu_steps</span><span class="p">,</span>
                                 <span class="n">cond</span><span class="o">=</span><span class="n">cond</span><span class="p">,</span>
                                 <span class="n">seebeck</span><span class="o">=</span><span class="n">seebeck</span><span class="p">,</span>
                                 <span class="n">kappa</span><span class="o">=</span><span class="n">kappa</span><span class="p">,</span>
                                 <span class="n">hall</span><span class="o">=</span><span class="n">hall</span><span class="p">,</span>
                                 <span class="n">doping</span><span class="o">=</span><span class="n">doping</span><span class="p">,</span>
                                 <span class="n">mu_doping</span><span class="o">=</span><span class="n">mu_doping</span><span class="p">,</span>
                                 <span class="n">seebeck_doping</span><span class="o">=</span><span class="n">seebeck_doping</span><span class="p">,</span>
                                 <span class="n">cond_doping</span><span class="o">=</span><span class="n">cond_doping</span><span class="p">,</span>
                                 <span class="n">kappa_doping</span><span class="o">=</span><span class="n">kappa_doping</span><span class="p">,</span>
                                 <span class="n">hall_doping</span><span class="o">=</span><span class="n">hall_doping</span><span class="p">,</span>
                                 <span class="n">dos</span><span class="o">=</span><span class="n">dos</span><span class="p">,</span>
                                 <span class="n">dos_partial</span><span class="o">=</span><span class="n">dos_partial</span><span class="p">,</span>
                                 <span class="n">carrier_conc</span><span class="o">=</span><span class="n">carrier_conc</span><span class="p">,</span>
                                 <span class="n">vol</span><span class="o">=</span><span class="n">vol</span><span class="p">,</span>
                                 <span class="n">warning</span><span class="o">=</span><span class="n">warning</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="read_cube_file"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.read_cube_file">[docs]</a><span class="k">def</span> <span class="nf">read_cube_file</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    :param filename: Cube filename</span>
<span class="sd">    :return: Energy data.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;rt&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
        <span class="n">natoms</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">count_line</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">count_line</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span> <span class="s2">&quot;CUBE&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;CUBE file format not recognized&quot;</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">count_line</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                <span class="n">tokens</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">natoms</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">tokens</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">count_line</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                <span class="n">tokens</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">n1</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">tokens</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="k">elif</span> <span class="n">count_line</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
                <span class="n">tokens</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">n2</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">tokens</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="k">elif</span> <span class="n">count_line</span> <span class="o">==</span> <span class="mi">5</span><span class="p">:</span>
                <span class="n">tokens</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">n3</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">tokens</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="k">elif</span> <span class="n">count_line</span> <span class="o">&gt;</span> <span class="mi">5</span><span class="p">:</span>
                <span class="k">break</span>

            <span class="n">count_line</span> <span class="o">+=</span> <span class="mi">1</span>

    <span class="k">if</span> <span class="s1">&#39;fort.30&#39;</span> <span class="ow">in</span> <span class="n">filename</span><span class="p">:</span>
        <span class="n">energy_data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">genfromtxt</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">skip_header</span><span class="o">=</span><span class="n">natoms</span> <span class="o">+</span> <span class="mi">6</span><span class="p">,</span> <span class="n">skip_footer</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">nlines_data</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">energy_data</span><span class="p">)</span>
        <span class="n">last_line</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">genfromtxt</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">skip_header</span><span class="o">=</span><span class="n">nlines_data</span> <span class="o">+</span> <span class="n">natoms</span> <span class="o">+</span> <span class="mi">6</span><span class="p">)</span>
        <span class="n">energy_data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">energy_data</span><span class="o">.</span><span class="n">flatten</span><span class="p">(),</span> <span class="n">last_line</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">n1</span><span class="p">,</span> <span class="n">n2</span><span class="p">,</span> <span class="n">n3</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s1">&#39;boltztrap_BZ.cube&#39;</span> <span class="ow">in</span> <span class="n">filename</span><span class="p">:</span>
        <span class="n">energy_data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">loadtxt</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">skiprows</span><span class="o">=</span><span class="n">natoms</span> <span class="o">+</span> <span class="mi">6</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">n1</span><span class="p">,</span> <span class="n">n2</span><span class="p">,</span> <span class="n">n3</span><span class="p">)</span>

    <span class="n">energy_data</span> <span class="o">/=</span> <span class="n">Energy</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;eV&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ry&quot;</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">energy_data</span></div>


<div class="viewcode-block" id="compare_sym_bands"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.compare_sym_bands">[docs]</a><span class="k">def</span> <span class="nf">compare_sym_bands</span><span class="p">(</span><span class="n">bands_obj</span><span class="p">,</span> <span class="n">bands_ref_obj</span><span class="p">,</span> <span class="n">nb</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Compute the mean of correlation between bzt and vasp bandstructure on</span>
<span class="sd">    sym line, for all bands and locally (for each branches) the difference</span>
<span class="sd">    squared (%) if nb is specified.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="n">bands_ref_obj</span><span class="o">.</span><span class="n">is_spin_polarized</span><span class="p">:</span>
        <span class="n">nbands</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">bands_obj</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">,</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">bands_ref_obj</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="c1"># TODO: why is this needed? Shouldn&#39;t pmg take care of nb_bands?</span>
        <span class="n">nbands</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">bands_obj</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]),</span>
                     <span class="nb">len</span><span class="p">(</span><span class="n">bands_ref_obj</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]))</span>
    <span class="c1"># print(nbands)</span>
    <span class="n">arr_bands</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">bands_obj</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][:</span><span class="n">nbands</span><span class="p">])</span>
    <span class="c1"># arr_bands_lavg = (arr_bands-np.mean(arr_bands,axis=1).reshape(nbands,1))</span>

    <span class="k">if</span> <span class="n">bands_ref_obj</span><span class="o">.</span><span class="n">is_spin_polarized</span><span class="p">:</span>
        <span class="n">arr_bands_ref_up</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">bands_ref_obj</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">])</span>
        <span class="n">arr_bands_ref_dw</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">bands_ref_obj</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">])</span>
        <span class="c1"># print(arr_bands_ref_up.shape)</span>
        <span class="n">arr_bands_ref</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">((</span><span class="n">arr_bands_ref_up</span><span class="p">,</span> <span class="n">arr_bands_ref_dw</span><span class="p">))</span>
        <span class="n">arr_bands_ref</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">arr_bands_ref</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)[:</span><span class="n">nbands</span><span class="p">]</span>
        <span class="c1"># print(arr_bands_ref.shape)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">arr_bands_ref</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">bands_ref_obj</span><span class="o">.</span><span class="n">bands</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][:</span><span class="n">nbands</span><span class="p">])</span>

    <span class="c1"># arr_bands_ref_lavg =</span>
    <span class="c1"># (arr_bands_ref-np.mean(arr_bands_ref,axis=1).reshape(nbands,1))</span>

    <span class="c1"># err = np.sum((arr_bands_lavg-arr_bands_ref_lavg)**2,axis=1)/nkpt</span>
    <span class="n">corr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span>
        <span class="p">[</span><span class="n">distance</span><span class="o">.</span><span class="n">correlation</span><span class="p">(</span><span class="n">arr_bands</span><span class="p">[</span><span class="n">idx</span><span class="p">],</span> <span class="n">arr_bands_ref</span><span class="p">[</span><span class="n">idx</span><span class="p">])</span> <span class="k">for</span> <span class="n">idx</span> <span class="ow">in</span>
         <span class="nb">range</span><span class="p">(</span><span class="n">nbands</span><span class="p">)])</span>

    <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">nb</span><span class="p">)</span> <span class="o">==</span> <span class="nb">int</span><span class="p">:</span>
        <span class="n">nb</span> <span class="o">=</span> <span class="p">[</span><span class="n">nb</span><span class="p">]</span>

    <span class="n">bcheck</span> <span class="o">=</span> <span class="p">{}</span>

    <span class="k">if</span> <span class="nb">max</span><span class="p">(</span><span class="n">nb</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">nbands</span><span class="p">:</span>
        <span class="n">branches</span> <span class="o">=</span> <span class="p">[[</span><span class="n">s</span><span class="p">[</span><span class="s1">&#39;start_index&#39;</span><span class="p">],</span> <span class="n">s</span><span class="p">[</span><span class="s1">&#39;end_index&#39;</span><span class="p">],</span> <span class="n">s</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">]]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span>
                    <span class="n">bands_ref_obj</span><span class="o">.</span><span class="n">branches</span><span class="p">]</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">bands_obj</span><span class="o">.</span><span class="n">is_metal</span><span class="p">()</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">bands_ref_obj</span><span class="o">.</span><span class="n">is_metal</span><span class="p">():</span>
            <span class="n">zero_ref</span> <span class="o">=</span> <span class="n">bands_ref_obj</span><span class="o">.</span><span class="n">get_vbm</span><span class="p">()[</span><span class="s1">&#39;energy&#39;</span><span class="p">]</span>
            <span class="n">zero</span> <span class="o">=</span> <span class="n">bands_obj</span><span class="o">.</span><span class="n">get_vbm</span><span class="p">()[</span><span class="s1">&#39;energy&#39;</span><span class="p">]</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">zero</span><span class="p">:</span>
                <span class="n">vbm</span> <span class="o">=</span> <span class="n">bands_ref_obj</span><span class="o">.</span><span class="n">get_vbm</span><span class="p">()[</span><span class="s1">&#39;band_index&#39;</span><span class="p">][</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
                <span class="n">zero</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">arr_bands</span><span class="p">[</span><span class="n">vbm</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">zero_ref</span> <span class="o">=</span> <span class="mi">0</span>  <span class="c1"># bands_ref_obj.efermi</span>
            <span class="n">zero</span> <span class="o">=</span> <span class="mi">0</span>  <span class="c1"># bands_obj.efermi</span>
            <span class="nb">print</span><span class="p">(</span><span class="n">zero</span><span class="p">,</span> <span class="n">zero_ref</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">nbi</span> <span class="ow">in</span> <span class="n">nb</span><span class="p">:</span>
            <span class="n">bcheck</span><span class="p">[</span><span class="n">nbi</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>

            <span class="n">bcheck</span><span class="p">[</span><span class="n">nbi</span><span class="p">][</span><span class="s1">&#39;Dist&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">arr_bands</span><span class="p">[</span><span class="n">nbi</span><span class="p">]</span> <span class="o">-</span> <span class="n">zero</span>
                                              <span class="o">-</span> <span class="n">arr_bands_ref</span><span class="p">[</span><span class="n">nbi</span><span class="p">]</span> <span class="o">+</span> <span class="n">zero_ref</span><span class="p">))</span>
            <span class="n">bcheck</span><span class="p">[</span><span class="n">nbi</span><span class="p">][</span><span class="s1">&#39;Corr&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">corr</span><span class="p">[</span><span class="n">nbi</span><span class="p">]</span>

            <span class="k">for</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">branches</span><span class="p">:</span>
                <span class="c1"># werr.append((sum((arr_bands_corr[nb][start:end+1] -</span>
                <span class="c1"># arr_bands_ref_corr[nb][start:end+1])**2)/(end+1-start)*100,name))</span>
                <span class="n">bcheck</span><span class="p">[</span><span class="n">nbi</span><span class="p">][</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">arr_bands</span><span class="p">[</span><span class="n">nbi</span><span class="p">][</span><span class="n">start</span><span class="p">:</span><span class="n">end</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
                                                <span class="o">-</span> <span class="n">zero</span>
                                                <span class="o">-</span> <span class="n">arr_bands_ref</span><span class="p">[</span><span class="n">nbi</span><span class="p">][</span>
                                                  <span class="n">start</span><span class="p">:</span><span class="n">end</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">zero_ref</span><span class="p">))</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">bcheck</span> <span class="o">=</span> <span class="s2">&quot;No nb given&quot;</span>

    <span class="k">return</span> <span class="n">bcheck</span></div>


<div class="viewcode-block" id="seebeck_spb"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.seebeck_spb">[docs]</a><span class="k">def</span> <span class="nf">seebeck_spb</span><span class="p">(</span><span class="n">eta</span><span class="p">,</span> <span class="n">Lambda</span><span class="o">=</span><span class="mf">0.5</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Seebeck analytic formula in the single parabolic model</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="kn">from</span> <span class="nn">fdint</span> <span class="kn">import</span> <span class="n">fdk</span>

    <span class="k">return</span> <span class="n">constants</span><span class="o">.</span><span class="n">k</span> <span class="o">/</span> <span class="n">constants</span><span class="o">.</span><span class="n">e</span> <span class="o">*</span> <span class="p">((</span><span class="mf">2.</span> <span class="o">+</span> <span class="n">Lambda</span><span class="p">)</span> <span class="o">*</span> <span class="n">fdk</span><span class="p">(</span><span class="mf">1.</span> <span class="o">+</span> <span class="n">Lambda</span><span class="p">,</span> <span class="n">eta</span><span class="p">)</span> <span class="o">/</span>
                                        <span class="p">((</span><span class="mf">1.</span> <span class="o">+</span> <span class="n">Lambda</span><span class="p">)</span> <span class="o">*</span> <span class="n">fdk</span><span class="p">(</span><span class="n">Lambda</span><span class="p">,</span> <span class="n">eta</span><span class="p">))</span> <span class="o">-</span> <span class="n">eta</span><span class="p">)</span> <span class="o">*</span> <span class="mf">1e+6</span></div>


<div class="viewcode-block" id="eta_from_seebeck"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.eta_from_seebeck">[docs]</a><span class="k">def</span> <span class="nf">eta_from_seebeck</span><span class="p">(</span><span class="n">seeb</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        It takes a value of seebeck and adjusts the analytic seebeck until it&#39;s equal</span>
<span class="sd">        Returns: eta where the two seebeck coefficients are equal</span>
<span class="sd">        (reduced chemical potential)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="kn">from</span> <span class="nn">scipy.optimize</span> <span class="kn">import</span> <span class="n">fsolve</span>
    <span class="n">out</span> <span class="o">=</span> <span class="n">fsolve</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="p">(</span><span class="n">seebeck_spb</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">)</span> <span class="o">-</span> <span class="nb">abs</span><span class="p">(</span><span class="n">seeb</span><span class="p">))</span> <span class="o">**</span> <span class="mi">2</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span> <span class="n">full_output</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">out</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span></div>


<div class="viewcode-block" id="seebeck_eff_mass_from_carr"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.seebeck_eff_mass_from_carr">[docs]</a><span class="k">def</span> <span class="nf">seebeck_eff_mass_from_carr</span><span class="p">(</span><span class="n">eta</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Calculate seebeck effective mass at a certain carrier concentration</span>
<span class="sd">    eta in kB*T units, n in cm-3, T in K, returns mass in m0 units</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="kn">from</span> <span class="nn">fdint</span> <span class="kn">import</span> <span class="n">fdk</span>
    <span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">BoltztrapError</span><span class="p">(</span><span class="s2">&quot;fdint module not found. Please, install it.</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
                             <span class="s2">&quot;It is needed to calculate Fermi integral quickly.&quot;</span><span class="p">)</span>

    <span class="k">return</span> <span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">*</span> <span class="nb">abs</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="o">*</span> <span class="mi">10</span> <span class="o">**</span> <span class="mi">6</span> <span class="o">/</span> <span class="p">(</span><span class="n">fdk</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">eta</span><span class="p">)))</span> <span class="o">**</span> <span class="p">(</span><span class="mf">2.</span> <span class="o">/</span> <span class="mi">3</span><span class="p">)</span> <span class="o">/</span> \
           <span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">constants</span><span class="o">.</span><span class="n">m_e</span> <span class="o">*</span> <span class="n">constants</span><span class="o">.</span><span class="n">k</span> <span class="o">*</span> <span class="n">T</span> <span class="o">/</span> <span class="p">(</span><span class="n">constants</span><span class="o">.</span><span class="n">h</span> <span class="o">/</span> <span class="mi">2</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">)</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span></div>


<div class="viewcode-block" id="seebeck_eff_mass_from_seebeck_carr"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.boltztrap.html#pymatgen.electronic_structure.boltztrap.seebeck_eff_mass_from_seebeck_carr">[docs]</a><span class="k">def</span> <span class="nf">seebeck_eff_mass_from_seebeck_carr</span><span class="p">(</span><span class="n">seeb</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Find the chemical potential where analytic and calculated seebeck are identical</span>
<span class="sd">    and then calculate the seebeck effective mass at that chemical potential and</span>
<span class="sd">    a certain carrier concentration n</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">eta</span> <span class="o">=</span> <span class="n">eta_from_seebeck</span><span class="p">(</span><span class="n">seeb</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">)</span>
    <span class="n">mass</span> <span class="o">=</span> <span class="n">seebeck_eff_mass_from_carr</span><span class="p">(</span><span class="n">eta</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">Lambda</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">mass</span></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.electronic_structure.boltztrap</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>